Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm/damon/test/core-kunit: add damon_apply_min_nr_regions() test

Add a kunit test for the functionality of damon_apply_min_nr_regions().

Link: https://lkml.kernel.org/r/20260228222831.7232-4-sj@kernel.org
Signed-off-by: SeongJae Park <sj@kernel.org>
Cc: Brendan Higgins <brendan.higgins@linux.dev>
Cc: David Gow <davidgow@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

SeongJae Park and committed by
Andrew Morton
ca6969e0 442d87c7

+52
+52
mm/damon/tests/core-kunit.h
··· 1239 1239 damos_free_filter(target_filter); 1240 1240 } 1241 1241 1242 + static void damon_test_apply_min_nr_regions_for(struct kunit *test, 1243 + unsigned long sz_regions, unsigned long min_region_sz, 1244 + unsigned long min_nr_regions, 1245 + unsigned long max_region_sz_expect, 1246 + unsigned long nr_regions_expect) 1247 + { 1248 + struct damon_ctx *ctx; 1249 + struct damon_target *t; 1250 + struct damon_region *r; 1251 + unsigned long max_region_size; 1252 + 1253 + ctx = damon_new_ctx(); 1254 + if (!ctx) 1255 + kunit_skip(test, "ctx alloc fail\n"); 1256 + t = damon_new_target(); 1257 + if (!t) { 1258 + damon_destroy_ctx(ctx); 1259 + kunit_skip(test, "target alloc fail\n"); 1260 + } 1261 + damon_add_target(ctx, t); 1262 + r = damon_new_region(0, sz_regions); 1263 + if (!r) { 1264 + damon_destroy_ctx(ctx); 1265 + kunit_skip(test, "region alloc fail\n"); 1266 + } 1267 + damon_add_region(r, t); 1268 + 1269 + ctx->min_region_sz = min_region_sz; 1270 + ctx->attrs.min_nr_regions = min_nr_regions; 1271 + max_region_size = damon_apply_min_nr_regions(ctx); 1272 + 1273 + KUNIT_EXPECT_EQ(test, max_region_size, max_region_sz_expect); 1274 + KUNIT_EXPECT_EQ(test, damon_nr_regions(t), nr_regions_expect); 1275 + 1276 + damon_destroy_ctx(ctx); 1277 + } 1278 + 1279 + static void damon_test_apply_min_nr_regions(struct kunit *test) 1280 + { 1281 + /* common, expected setup */ 1282 + damon_test_apply_min_nr_regions_for(test, 10, 1, 10, 1, 10); 1283 + /* no zero size limit */ 1284 + damon_test_apply_min_nr_regions_for(test, 10, 1, 15, 1, 10); 1285 + /* max size should be aligned by min_region_sz */ 1286 + damon_test_apply_min_nr_regions_for(test, 10, 2, 2, 6, 2); 1287 + /* 1288 + * when min_nr_regions and min_region_sz conflicts, min_region_sz wins. 1289 + */ 1290 + damon_test_apply_min_nr_regions_for(test, 10, 2, 10, 2, 5); 1291 + } 1292 + 1242 1293 static struct kunit_case damon_test_cases[] = { 1243 1294 KUNIT_CASE(damon_test_target), 1244 1295 KUNIT_CASE(damon_test_regions), ··· 1316 1265 KUNIT_CASE(damos_test_filter_out), 1317 1266 KUNIT_CASE(damon_test_feed_loop_next_input), 1318 1267 KUNIT_CASE(damon_test_set_filters_default_reject), 1268 + KUNIT_CASE(damon_test_apply_min_nr_regions), 1319 1269 {}, 1320 1270 }; 1321 1271