xref: /linux/mm/damon/tests/vaddr-kunit.h (revision 3a39d672e7f48b8d6b91a09afa4b55352773b4b5)
19bfbaa5eSSeongJae Park /* SPDX-License-Identifier: GPL-2.0 */
29bfbaa5eSSeongJae Park /*
39bfbaa5eSSeongJae Park  * Data Access Monitor Unit Tests
49bfbaa5eSSeongJae Park  *
59bfbaa5eSSeongJae Park  * Copyright 2019 Amazon.com, Inc. or its affiliates.  All rights reserved.
69bfbaa5eSSeongJae Park  *
79bfbaa5eSSeongJae Park  * Author: SeongJae Park <sj@kernel.org>
89bfbaa5eSSeongJae Park  */
99bfbaa5eSSeongJae Park 
109bfbaa5eSSeongJae Park #ifdef CONFIG_DAMON_VADDR_KUNIT_TEST
119bfbaa5eSSeongJae Park 
129bfbaa5eSSeongJae Park #ifndef _DAMON_VADDR_TEST_H
139bfbaa5eSSeongJae Park #define _DAMON_VADDR_TEST_H
149bfbaa5eSSeongJae Park 
159bfbaa5eSSeongJae Park #include <kunit/test.h>
169bfbaa5eSSeongJae Park 
__link_vmas(struct maple_tree * mt,struct vm_area_struct * vmas,ssize_t nr_vmas)179bfbaa5eSSeongJae Park static int __link_vmas(struct maple_tree *mt, struct vm_area_struct *vmas,
189bfbaa5eSSeongJae Park 			ssize_t nr_vmas)
199bfbaa5eSSeongJae Park {
209bfbaa5eSSeongJae Park 	int i, ret = -ENOMEM;
219bfbaa5eSSeongJae Park 	MA_STATE(mas, mt, 0, 0);
229bfbaa5eSSeongJae Park 
239bfbaa5eSSeongJae Park 	if (!nr_vmas)
249bfbaa5eSSeongJae Park 		return 0;
259bfbaa5eSSeongJae Park 
269bfbaa5eSSeongJae Park 	mas_lock(&mas);
279bfbaa5eSSeongJae Park 	for (i = 0; i < nr_vmas; i++) {
289bfbaa5eSSeongJae Park 		mas_set_range(&mas, vmas[i].vm_start, vmas[i].vm_end - 1);
299bfbaa5eSSeongJae Park 		if (mas_store_gfp(&mas, &vmas[i], GFP_KERNEL))
309bfbaa5eSSeongJae Park 			goto failed;
319bfbaa5eSSeongJae Park 	}
329bfbaa5eSSeongJae Park 
339bfbaa5eSSeongJae Park 	ret = 0;
349bfbaa5eSSeongJae Park failed:
359bfbaa5eSSeongJae Park 	mas_unlock(&mas);
369bfbaa5eSSeongJae Park 	return ret;
379bfbaa5eSSeongJae Park }
389bfbaa5eSSeongJae Park 
399bfbaa5eSSeongJae Park /*
409bfbaa5eSSeongJae Park  * Test __damon_va_three_regions() function
419bfbaa5eSSeongJae Park  *
429bfbaa5eSSeongJae Park  * In case of virtual memory address spaces monitoring, DAMON converts the
439bfbaa5eSSeongJae Park  * complex and dynamic memory mappings of each target task to three
449bfbaa5eSSeongJae Park  * discontiguous regions which cover every mapped areas.  However, the three
459bfbaa5eSSeongJae Park  * regions should not include the two biggest unmapped areas in the original
469bfbaa5eSSeongJae Park  * mapping, because the two biggest areas are normally the areas between 1)
479bfbaa5eSSeongJae Park  * heap and the mmap()-ed regions, and 2) the mmap()-ed regions and stack.
489bfbaa5eSSeongJae Park  * Because these two unmapped areas are very huge but obviously never accessed,
499bfbaa5eSSeongJae Park  * covering the region is just a waste.
509bfbaa5eSSeongJae Park  *
519bfbaa5eSSeongJae Park  * '__damon_va_three_regions() receives an address space of a process.  It
529bfbaa5eSSeongJae Park  * first identifies the start of mappings, end of mappings, and the two biggest
539bfbaa5eSSeongJae Park  * unmapped areas.  After that, based on the information, it constructs the
549bfbaa5eSSeongJae Park  * three regions and returns.  For more detail, refer to the comment of
559bfbaa5eSSeongJae Park  * 'damon_init_regions_of()' function definition in 'mm/damon.c' file.
569bfbaa5eSSeongJae Park  *
579bfbaa5eSSeongJae Park  * For example, suppose virtual address ranges of 10-20, 20-25, 200-210,
589bfbaa5eSSeongJae Park  * 210-220, 300-305, and 307-330 (Other comments represent this mappings in
599bfbaa5eSSeongJae Park  * more short form: 10-20-25, 200-210-220, 300-305, 307-330) of a process are
609bfbaa5eSSeongJae Park  * mapped.  To cover every mappings, the three regions should start with 10,
619bfbaa5eSSeongJae Park  * and end with 305.  The process also has three unmapped areas, 25-200,
629bfbaa5eSSeongJae Park  * 220-300, and 305-307.  Among those, 25-200 and 220-300 are the biggest two
639bfbaa5eSSeongJae Park  * unmapped areas, and thus it should be converted to three regions of 10-25,
649bfbaa5eSSeongJae Park  * 200-220, and 300-330.
659bfbaa5eSSeongJae Park  */
damon_test_three_regions_in_vmas(struct kunit * test)669bfbaa5eSSeongJae Park static void damon_test_three_regions_in_vmas(struct kunit *test)
679bfbaa5eSSeongJae Park {
689bfbaa5eSSeongJae Park 	static struct mm_struct mm;
699bfbaa5eSSeongJae Park 	struct damon_addr_range regions[3] = {0,};
709bfbaa5eSSeongJae Park 	/* 10-20-25, 200-210-220, 300-305, 307-330 */
719bfbaa5eSSeongJae Park 	struct vm_area_struct vmas[] = {
729bfbaa5eSSeongJae Park 		(struct vm_area_struct) {.vm_start = 10, .vm_end = 20},
739bfbaa5eSSeongJae Park 		(struct vm_area_struct) {.vm_start = 20, .vm_end = 25},
749bfbaa5eSSeongJae Park 		(struct vm_area_struct) {.vm_start = 200, .vm_end = 210},
759bfbaa5eSSeongJae Park 		(struct vm_area_struct) {.vm_start = 210, .vm_end = 220},
769bfbaa5eSSeongJae Park 		(struct vm_area_struct) {.vm_start = 300, .vm_end = 305},
779bfbaa5eSSeongJae Park 		(struct vm_area_struct) {.vm_start = 307, .vm_end = 330},
789bfbaa5eSSeongJae Park 	};
799bfbaa5eSSeongJae Park 
80*f0679f9eSSeongJae Park 	mt_init_flags(&mm.mm_mt, MT_FLAGS_ALLOC_RANGE | MT_FLAGS_USE_RCU);
819bfbaa5eSSeongJae Park 	if (__link_vmas(&mm.mm_mt, vmas, ARRAY_SIZE(vmas)))
829bfbaa5eSSeongJae Park 		kunit_skip(test, "Failed to create VMA tree");
839bfbaa5eSSeongJae Park 
849bfbaa5eSSeongJae Park 	__damon_va_three_regions(&mm, regions);
859bfbaa5eSSeongJae Park 
869bfbaa5eSSeongJae Park 	KUNIT_EXPECT_EQ(test, 10ul, regions[0].start);
879bfbaa5eSSeongJae Park 	KUNIT_EXPECT_EQ(test, 25ul, regions[0].end);
889bfbaa5eSSeongJae Park 	KUNIT_EXPECT_EQ(test, 200ul, regions[1].start);
899bfbaa5eSSeongJae Park 	KUNIT_EXPECT_EQ(test, 220ul, regions[1].end);
909bfbaa5eSSeongJae Park 	KUNIT_EXPECT_EQ(test, 300ul, regions[2].start);
919bfbaa5eSSeongJae Park 	KUNIT_EXPECT_EQ(test, 330ul, regions[2].end);
929bfbaa5eSSeongJae Park }
939bfbaa5eSSeongJae Park 
__nth_region_of(struct damon_target * t,int idx)949bfbaa5eSSeongJae Park static struct damon_region *__nth_region_of(struct damon_target *t, int idx)
959bfbaa5eSSeongJae Park {
969bfbaa5eSSeongJae Park 	struct damon_region *r;
979bfbaa5eSSeongJae Park 	unsigned int i = 0;
989bfbaa5eSSeongJae Park 
999bfbaa5eSSeongJae Park 	damon_for_each_region(r, t) {
1009bfbaa5eSSeongJae Park 		if (i++ == idx)
1019bfbaa5eSSeongJae Park 			return r;
1029bfbaa5eSSeongJae Park 	}
1039bfbaa5eSSeongJae Park 
1049bfbaa5eSSeongJae Park 	return NULL;
1059bfbaa5eSSeongJae Park }
1069bfbaa5eSSeongJae Park 
1079bfbaa5eSSeongJae Park /*
1089bfbaa5eSSeongJae Park  * Test 'damon_set_regions()'
1099bfbaa5eSSeongJae Park  *
1109bfbaa5eSSeongJae Park  * test			kunit object
1119bfbaa5eSSeongJae Park  * regions		an array containing start/end addresses of current
1129bfbaa5eSSeongJae Park  *			monitoring target regions
1139bfbaa5eSSeongJae Park  * nr_regions		the number of the addresses in 'regions'
1149bfbaa5eSSeongJae Park  * three_regions	The three regions that need to be applied now
1159bfbaa5eSSeongJae Park  * expected		start/end addresses of monitoring target regions that
1169bfbaa5eSSeongJae Park  *			'three_regions' are applied
1179bfbaa5eSSeongJae Park  * nr_expected		the number of addresses in 'expected'
1189bfbaa5eSSeongJae Park  *
1199bfbaa5eSSeongJae Park  * The memory mapping of the target processes changes dynamically.  To follow
1209bfbaa5eSSeongJae Park  * the change, DAMON periodically reads the mappings, simplifies it to the
1219bfbaa5eSSeongJae Park  * three regions, and updates the monitoring target regions to fit in the three
1229bfbaa5eSSeongJae Park  * regions.  The update of current target regions is the role of
1239bfbaa5eSSeongJae Park  * 'damon_set_regions()'.
1249bfbaa5eSSeongJae Park  *
1259bfbaa5eSSeongJae Park  * This test passes the given target regions and the new three regions that
1269bfbaa5eSSeongJae Park  * need to be applied to the function and check whether it updates the regions
1279bfbaa5eSSeongJae Park  * as expected.
1289bfbaa5eSSeongJae Park  */
damon_do_test_apply_three_regions(struct kunit * test,unsigned long * regions,int nr_regions,struct damon_addr_range * three_regions,unsigned long * expected,int nr_expected)1299bfbaa5eSSeongJae Park static void damon_do_test_apply_three_regions(struct kunit *test,
1309bfbaa5eSSeongJae Park 				unsigned long *regions, int nr_regions,
1319bfbaa5eSSeongJae Park 				struct damon_addr_range *three_regions,
1329bfbaa5eSSeongJae Park 				unsigned long *expected, int nr_expected)
1339bfbaa5eSSeongJae Park {
1349bfbaa5eSSeongJae Park 	struct damon_target *t;
1359bfbaa5eSSeongJae Park 	struct damon_region *r;
1369bfbaa5eSSeongJae Park 	int i;
1379bfbaa5eSSeongJae Park 
1389bfbaa5eSSeongJae Park 	t = damon_new_target();
1399bfbaa5eSSeongJae Park 	for (i = 0; i < nr_regions / 2; i++) {
1409bfbaa5eSSeongJae Park 		r = damon_new_region(regions[i * 2], regions[i * 2 + 1]);
1419bfbaa5eSSeongJae Park 		damon_add_region(r, t);
1429bfbaa5eSSeongJae Park 	}
1439bfbaa5eSSeongJae Park 
1449bfbaa5eSSeongJae Park 	damon_set_regions(t, three_regions, 3);
1459bfbaa5eSSeongJae Park 
1469bfbaa5eSSeongJae Park 	for (i = 0; i < nr_expected / 2; i++) {
1479bfbaa5eSSeongJae Park 		r = __nth_region_of(t, i);
1489bfbaa5eSSeongJae Park 		KUNIT_EXPECT_EQ(test, r->ar.start, expected[i * 2]);
1499bfbaa5eSSeongJae Park 		KUNIT_EXPECT_EQ(test, r->ar.end, expected[i * 2 + 1]);
1509bfbaa5eSSeongJae Park 	}
1519bfbaa5eSSeongJae Park 
1529bfbaa5eSSeongJae Park 	damon_destroy_target(t);
1539bfbaa5eSSeongJae Park }
1549bfbaa5eSSeongJae Park 
1559bfbaa5eSSeongJae Park /*
1569bfbaa5eSSeongJae Park  * This function test most common case where the three big regions are only
1579bfbaa5eSSeongJae Park  * slightly changed.  Target regions should adjust their boundary (10-20-30,
1589bfbaa5eSSeongJae Park  * 50-55, 70-80, 90-100) to fit with the new big regions or remove target
1599bfbaa5eSSeongJae Park  * regions (57-79) that now out of the three regions.
1609bfbaa5eSSeongJae Park  */
damon_test_apply_three_regions1(struct kunit * test)1619bfbaa5eSSeongJae Park static void damon_test_apply_three_regions1(struct kunit *test)
1629bfbaa5eSSeongJae Park {
1639bfbaa5eSSeongJae Park 	/* 10-20-30, 50-55-57-59, 70-80-90-100 */
1649bfbaa5eSSeongJae Park 	unsigned long regions[] = {10, 20, 20, 30, 50, 55, 55, 57, 57, 59,
1659bfbaa5eSSeongJae Park 				70, 80, 80, 90, 90, 100};
1669bfbaa5eSSeongJae Park 	/* 5-27, 45-55, 73-104 */
1679bfbaa5eSSeongJae Park 	struct damon_addr_range new_three_regions[3] = {
1689bfbaa5eSSeongJae Park 		(struct damon_addr_range){.start = 5, .end = 27},
1699bfbaa5eSSeongJae Park 		(struct damon_addr_range){.start = 45, .end = 55},
1709bfbaa5eSSeongJae Park 		(struct damon_addr_range){.start = 73, .end = 104} };
1719bfbaa5eSSeongJae Park 	/* 5-20-27, 45-55, 73-80-90-104 */
1729bfbaa5eSSeongJae Park 	unsigned long expected[] = {5, 20, 20, 27, 45, 55,
1739bfbaa5eSSeongJae Park 				73, 80, 80, 90, 90, 104};
1749bfbaa5eSSeongJae Park 
1759bfbaa5eSSeongJae Park 	damon_do_test_apply_three_regions(test, regions, ARRAY_SIZE(regions),
1769bfbaa5eSSeongJae Park 			new_three_regions, expected, ARRAY_SIZE(expected));
1779bfbaa5eSSeongJae Park }
1789bfbaa5eSSeongJae Park 
1799bfbaa5eSSeongJae Park /*
1809bfbaa5eSSeongJae Park  * Test slightly bigger change.  Similar to above, but the second big region
1819bfbaa5eSSeongJae Park  * now require two target regions (50-55, 57-59) to be removed.
1829bfbaa5eSSeongJae Park  */
damon_test_apply_three_regions2(struct kunit * test)1839bfbaa5eSSeongJae Park static void damon_test_apply_three_regions2(struct kunit *test)
1849bfbaa5eSSeongJae Park {
1859bfbaa5eSSeongJae Park 	/* 10-20-30, 50-55-57-59, 70-80-90-100 */
1869bfbaa5eSSeongJae Park 	unsigned long regions[] = {10, 20, 20, 30, 50, 55, 55, 57, 57, 59,
1879bfbaa5eSSeongJae Park 				70, 80, 80, 90, 90, 100};
1889bfbaa5eSSeongJae Park 	/* 5-27, 56-57, 65-104 */
1899bfbaa5eSSeongJae Park 	struct damon_addr_range new_three_regions[3] = {
1909bfbaa5eSSeongJae Park 		(struct damon_addr_range){.start = 5, .end = 27},
1919bfbaa5eSSeongJae Park 		(struct damon_addr_range){.start = 56, .end = 57},
1929bfbaa5eSSeongJae Park 		(struct damon_addr_range){.start = 65, .end = 104} };
1939bfbaa5eSSeongJae Park 	/* 5-20-27, 56-57, 65-80-90-104 */
1949bfbaa5eSSeongJae Park 	unsigned long expected[] = {5, 20, 20, 27, 56, 57,
1959bfbaa5eSSeongJae Park 				65, 80, 80, 90, 90, 104};
1969bfbaa5eSSeongJae Park 
1979bfbaa5eSSeongJae Park 	damon_do_test_apply_three_regions(test, regions, ARRAY_SIZE(regions),
1989bfbaa5eSSeongJae Park 			new_three_regions, expected, ARRAY_SIZE(expected));
1999bfbaa5eSSeongJae Park }
2009bfbaa5eSSeongJae Park 
2019bfbaa5eSSeongJae Park /*
2029bfbaa5eSSeongJae Park  * Test a big change.  The second big region has totally freed and mapped to
2039bfbaa5eSSeongJae Park  * different area (50-59 -> 61-63).  The target regions which were in the old
2049bfbaa5eSSeongJae Park  * second big region (50-55-57-59) should be removed and new target region
2059bfbaa5eSSeongJae Park  * covering the second big region (61-63) should be created.
2069bfbaa5eSSeongJae Park  */
damon_test_apply_three_regions3(struct kunit * test)2079bfbaa5eSSeongJae Park static void damon_test_apply_three_regions3(struct kunit *test)
2089bfbaa5eSSeongJae Park {
2099bfbaa5eSSeongJae Park 	/* 10-20-30, 50-55-57-59, 70-80-90-100 */
2109bfbaa5eSSeongJae Park 	unsigned long regions[] = {10, 20, 20, 30, 50, 55, 55, 57, 57, 59,
2119bfbaa5eSSeongJae Park 				70, 80, 80, 90, 90, 100};
2129bfbaa5eSSeongJae Park 	/* 5-27, 61-63, 65-104 */
2139bfbaa5eSSeongJae Park 	struct damon_addr_range new_three_regions[3] = {
2149bfbaa5eSSeongJae Park 		(struct damon_addr_range){.start = 5, .end = 27},
2159bfbaa5eSSeongJae Park 		(struct damon_addr_range){.start = 61, .end = 63},
2169bfbaa5eSSeongJae Park 		(struct damon_addr_range){.start = 65, .end = 104} };
2179bfbaa5eSSeongJae Park 	/* 5-20-27, 61-63, 65-80-90-104 */
2189bfbaa5eSSeongJae Park 	unsigned long expected[] = {5, 20, 20, 27, 61, 63,
2199bfbaa5eSSeongJae Park 				65, 80, 80, 90, 90, 104};
2209bfbaa5eSSeongJae Park 
2219bfbaa5eSSeongJae Park 	damon_do_test_apply_three_regions(test, regions, ARRAY_SIZE(regions),
2229bfbaa5eSSeongJae Park 			new_three_regions, expected, ARRAY_SIZE(expected));
2239bfbaa5eSSeongJae Park }
2249bfbaa5eSSeongJae Park 
2259bfbaa5eSSeongJae Park /*
2269bfbaa5eSSeongJae Park  * Test another big change.  Both of the second and third big regions (50-59
2279bfbaa5eSSeongJae Park  * and 70-100) has totally freed and mapped to different area (30-32 and
2289bfbaa5eSSeongJae Park  * 65-68).  The target regions which were in the old second and third big
2299bfbaa5eSSeongJae Park  * regions should now be removed and new target regions covering the new second
2309bfbaa5eSSeongJae Park  * and third big regions should be created.
2319bfbaa5eSSeongJae Park  */
damon_test_apply_three_regions4(struct kunit * test)2329bfbaa5eSSeongJae Park static void damon_test_apply_three_regions4(struct kunit *test)
2339bfbaa5eSSeongJae Park {
2349bfbaa5eSSeongJae Park 	/* 10-20-30, 50-55-57-59, 70-80-90-100 */
2359bfbaa5eSSeongJae Park 	unsigned long regions[] = {10, 20, 20, 30, 50, 55, 55, 57, 57, 59,
2369bfbaa5eSSeongJae Park 				70, 80, 80, 90, 90, 100};
2379bfbaa5eSSeongJae Park 	/* 5-7, 30-32, 65-68 */
2389bfbaa5eSSeongJae Park 	struct damon_addr_range new_three_regions[3] = {
2399bfbaa5eSSeongJae Park 		(struct damon_addr_range){.start = 5, .end = 7},
2409bfbaa5eSSeongJae Park 		(struct damon_addr_range){.start = 30, .end = 32},
2419bfbaa5eSSeongJae Park 		(struct damon_addr_range){.start = 65, .end = 68} };
2429bfbaa5eSSeongJae Park 	/* expect 5-7, 30-32, 65-68 */
2439bfbaa5eSSeongJae Park 	unsigned long expected[] = {5, 7, 30, 32, 65, 68};
2449bfbaa5eSSeongJae Park 
2459bfbaa5eSSeongJae Park 	damon_do_test_apply_three_regions(test, regions, ARRAY_SIZE(regions),
2469bfbaa5eSSeongJae Park 			new_three_regions, expected, ARRAY_SIZE(expected));
2479bfbaa5eSSeongJae Park }
2489bfbaa5eSSeongJae Park 
damon_test_split_evenly_fail(struct kunit * test,unsigned long start,unsigned long end,unsigned int nr_pieces)2499bfbaa5eSSeongJae Park static void damon_test_split_evenly_fail(struct kunit *test,
2509bfbaa5eSSeongJae Park 		unsigned long start, unsigned long end, unsigned int nr_pieces)
2519bfbaa5eSSeongJae Park {
2529bfbaa5eSSeongJae Park 	struct damon_target *t = damon_new_target();
2539bfbaa5eSSeongJae Park 	struct damon_region *r = damon_new_region(start, end);
2549bfbaa5eSSeongJae Park 
2559bfbaa5eSSeongJae Park 	damon_add_region(r, t);
2569bfbaa5eSSeongJae Park 	KUNIT_EXPECT_EQ(test,
2579bfbaa5eSSeongJae Park 			damon_va_evenly_split_region(t, r, nr_pieces), -EINVAL);
2589bfbaa5eSSeongJae Park 	KUNIT_EXPECT_EQ(test, damon_nr_regions(t), 1u);
2599bfbaa5eSSeongJae Park 
2609bfbaa5eSSeongJae Park 	damon_for_each_region(r, t) {
2619bfbaa5eSSeongJae Park 		KUNIT_EXPECT_EQ(test, r->ar.start, start);
2629bfbaa5eSSeongJae Park 		KUNIT_EXPECT_EQ(test, r->ar.end, end);
2639bfbaa5eSSeongJae Park 	}
2649bfbaa5eSSeongJae Park 
2659bfbaa5eSSeongJae Park 	damon_free_target(t);
2669bfbaa5eSSeongJae Park }
2679bfbaa5eSSeongJae Park 
damon_test_split_evenly_succ(struct kunit * test,unsigned long start,unsigned long end,unsigned int nr_pieces)2689bfbaa5eSSeongJae Park static void damon_test_split_evenly_succ(struct kunit *test,
2699bfbaa5eSSeongJae Park 	unsigned long start, unsigned long end, unsigned int nr_pieces)
2709bfbaa5eSSeongJae Park {
2719bfbaa5eSSeongJae Park 	struct damon_target *t = damon_new_target();
2729bfbaa5eSSeongJae Park 	struct damon_region *r = damon_new_region(start, end);
2739bfbaa5eSSeongJae Park 	unsigned long expected_width = (end - start) / nr_pieces;
2749bfbaa5eSSeongJae Park 	unsigned long i = 0;
2759bfbaa5eSSeongJae Park 
2769bfbaa5eSSeongJae Park 	damon_add_region(r, t);
2779bfbaa5eSSeongJae Park 	KUNIT_EXPECT_EQ(test,
2789bfbaa5eSSeongJae Park 			damon_va_evenly_split_region(t, r, nr_pieces), 0);
2799bfbaa5eSSeongJae Park 	KUNIT_EXPECT_EQ(test, damon_nr_regions(t), nr_pieces);
2809bfbaa5eSSeongJae Park 
2819bfbaa5eSSeongJae Park 	damon_for_each_region(r, t) {
2829bfbaa5eSSeongJae Park 		if (i == nr_pieces - 1) {
2839bfbaa5eSSeongJae Park 			KUNIT_EXPECT_EQ(test,
2849bfbaa5eSSeongJae Park 				r->ar.start, start + i * expected_width);
2859bfbaa5eSSeongJae Park 			KUNIT_EXPECT_EQ(test, r->ar.end, end);
2869bfbaa5eSSeongJae Park 			break;
2879bfbaa5eSSeongJae Park 		}
2889bfbaa5eSSeongJae Park 		KUNIT_EXPECT_EQ(test,
2899bfbaa5eSSeongJae Park 				r->ar.start, start + i++ * expected_width);
2909bfbaa5eSSeongJae Park 		KUNIT_EXPECT_EQ(test, r->ar.end, start + i * expected_width);
2919bfbaa5eSSeongJae Park 	}
2929bfbaa5eSSeongJae Park 	damon_free_target(t);
2939bfbaa5eSSeongJae Park }
2949bfbaa5eSSeongJae Park 
damon_test_split_evenly(struct kunit * test)2959bfbaa5eSSeongJae Park static void damon_test_split_evenly(struct kunit *test)
2969bfbaa5eSSeongJae Park {
2979bfbaa5eSSeongJae Park 	KUNIT_EXPECT_EQ(test, damon_va_evenly_split_region(NULL, NULL, 5),
2989bfbaa5eSSeongJae Park 			-EINVAL);
2999bfbaa5eSSeongJae Park 
3009bfbaa5eSSeongJae Park 	damon_test_split_evenly_fail(test, 0, 100, 0);
3019bfbaa5eSSeongJae Park 	damon_test_split_evenly_succ(test, 0, 100, 10);
3029bfbaa5eSSeongJae Park 	damon_test_split_evenly_succ(test, 5, 59, 5);
3039bfbaa5eSSeongJae Park 	damon_test_split_evenly_fail(test, 5, 6, 2);
3049bfbaa5eSSeongJae Park }
3059bfbaa5eSSeongJae Park 
3069bfbaa5eSSeongJae Park static struct kunit_case damon_test_cases[] = {
3079bfbaa5eSSeongJae Park 	KUNIT_CASE(damon_test_three_regions_in_vmas),
3089bfbaa5eSSeongJae Park 	KUNIT_CASE(damon_test_apply_three_regions1),
3099bfbaa5eSSeongJae Park 	KUNIT_CASE(damon_test_apply_three_regions2),
3109bfbaa5eSSeongJae Park 	KUNIT_CASE(damon_test_apply_three_regions3),
3119bfbaa5eSSeongJae Park 	KUNIT_CASE(damon_test_apply_three_regions4),
3129bfbaa5eSSeongJae Park 	KUNIT_CASE(damon_test_split_evenly),
3139bfbaa5eSSeongJae Park 	{},
3149bfbaa5eSSeongJae Park };
3159bfbaa5eSSeongJae Park 
3169bfbaa5eSSeongJae Park static struct kunit_suite damon_test_suite = {
3179bfbaa5eSSeongJae Park 	.name = "damon-operations",
3189bfbaa5eSSeongJae Park 	.test_cases = damon_test_cases,
3199bfbaa5eSSeongJae Park };
3209bfbaa5eSSeongJae Park kunit_test_suite(damon_test_suite);
3219bfbaa5eSSeongJae Park 
3229bfbaa5eSSeongJae Park #endif /* _DAMON_VADDR_TEST_H */
3239bfbaa5eSSeongJae Park 
3249bfbaa5eSSeongJae Park #endif	/* CONFIG_DAMON_VADDR_KUNIT_TEST */
325