Skip to contentSkip to conversation

misc fixups for DAMON {self,kunit} tests

PATCH Applied SeongJae Park 1 participant 10 messages Aug 27, 2024

Subsystems (3)
lore
Share & tools
lore

SeongJae Park

author maintainer
#0 lore raw

cover misc fixups for DAMON {self,kunit} tests

This patchset is for minor fixups of DAMON selftests and kunit tests. First three patches make DAMON selftests more cleanly maintained (patches 1 and 2) without unnecessary warnings (patch 3). Following six patches remove unnecessary test case (patch 4), handle configs combinations that can make tests fail (patches 5-7), reorganize the test files following the new guideline (patch 8), and add reference kunitconfig for DAMON kunit tests (patch 9).

SeongJae Park (9):
selftests/damon: add access_memory_even to .gitignore selftests/damon: cleanup __pycache__/ with 'make clean' selftests/damon: add execute permissions to test scripts mm/damon/core-test: test only vaddr case on ops registration test mm/damon/core-test: fix damon_test_ops_registration() for DAMON_VADDR
unset case
mm/damon/dbgfs-test: skip dbgfs_set_targets() test if PADDR is not
registered
mm/damon/dbgfs-test: skip dbgfs_set_init_regions() test if PADDR is
not registered
mm/damon: move kunit tests to tests/ subdirectory with _kunit suffix mm/damon/tests: add .kunitconfig file for DAMON kunit tests

 mm/damon/core.c                               |  2 +-
 mm/damon/dbgfs.c                              |  2 +-
 mm/damon/sysfs.c                              |  2 +-
 mm/damon/tests/.kunitconfig                   | 22 ++++++++++++++++++
 mm/damon/{core-test.h => tests/core-kunit.h}  | 23 ++++++++++++++-----
 .../{dbgfs-test.h => tests/dbgfs-kunit.h}     | 10 ++++++++
 .../{sysfs-test.h => tests/sysfs-kunit.h}     |  0
 .../{vaddr-test.h => tests/vaddr-kunit.h}     |  0
 mm/damon/vaddr.c                              |  2 +-
 tools/testing/selftests/damon/.gitignore      |  1 +
 tools/testing/selftests/damon/Makefile        |  2 ++
 .../selftests/damon/damon_nr_regions.py       |  0
 .../selftests/damon/damos_apply_interval.py   |  0
 tools/testing/selftests/damon/damos_quota.py  |  0
 .../selftests/damon/damos_quota_goal.py       |  0
 .../selftests/damon/damos_tried_regions.py    |  0
 .../damon/debugfs_target_ids_pid_leak.sh      |  0
 ...s_target_ids_read_before_terminate_race.sh |  0
 ...sysfs_update_schemes_tried_regions_hang.py |  0
 ...te_schemes_tried_regions_wss_estimation.py |  0
 20 files changed, 56 insertions(+), 10 deletions(-)
 create mode 100644 mm/damon/tests/.kunitconfig
 rename mm/damon/{core-test.h => tests/core-kunit.h} (96%)
 rename mm/damon/{dbgfs-test.h => tests/dbgfs-kunit.h} (94%)
 rename mm/damon/{sysfs-test.h => tests/sysfs-kunit.h} (100%)
 rename mm/damon/{vaddr-test.h => tests/vaddr-kunit.h} (100%)
 mode change 100644 => 100755 tools/testing/selftests/damon/damon_nr_regions.py
 mode change 100644 => 100755 tools/testing/selftests/damon/damos_apply_interval.py
 mode change 100644 => 100755 tools/testing/selftests/damon/damos_quota.py
 mode change 100644 => 100755 tools/testing/selftests/damon/damos_quota_goal.py
 mode change 100644 => 100755 tools/testing/selftests/damon/damos_tried_regions.py
 mode change 100644 => 100755 tools/testing/selftests/damon/debugfs_target_ids_pid_leak.sh
 mode change 100644 => 100755 tools/testing/selftests/damon/debugfs_target_ids_read_before_terminate_race.sh
 mode change 100644 => 100755 tools/testing/selftests/damon/sysfs_update_schemes_tried_regions_hang.py
 mode change 100644 => 100755 tools/testing/selftests/damon/sysfs_update_schemes_tried_regions_wss_estimation.py

base-commit: ac23a0bb201e9916faa357d51c387e523813b4ad

Signature · 1 line
2.39.2
author maintainer
#1 lore raw

PATCH 1/9 selftests/damon: add access_memory_even to .gitignore

DAMON selftests build access_memory_even, but its not on the .gitignore list. Add it to make 'git status' output cleaner.

Fixes commit c94df805c774 ("selftests/damon: implement a program for even-numbered memory regions access")
---
 tools/testing/selftests/damon/.gitignore | 1 +
 1 file changed, 1 insertion(+)
tools/testing/selftests/damon/.gitignore +1 -0
index e65ef9d9cedc..2ab675fecb6b 100644
@@ -3,3 +3,4 @@ huge_count_read_write
 debugfs_target_ids_read_before_terminate_race
 debugfs_target_ids_pid_leak
 access_memory
+access_memory_even
Signature · 1 line
2.39.2
author maintainer
#2 lore raw

PATCH 2/9 selftests/damon: cleanup __pycache__/ with 'make clean'

In reply to SeongJae Park

Python-based tests creates __pycache__/ directory. Remove it with 'make clean' by defining it as EXTRA_CLEAN.

Fixes b5906f5f7359 ("selftests/damon: add a test for update_schemes_tried_regions sysfs command")
---
 tools/testing/selftests/damon/Makefile | 2 ++
 1 file changed, 2 insertions(+)
tools/testing/selftests/damon/Makefile +2 -0
index 1e2e98cc809d..5b2a6a5dd1af 100644
@@ -25,4 +25,6 @@ TEST_PROGS += debugfs_target_ids_pid_leak.sh
 TEST_PROGS += sysfs_update_removed_scheme_dir.sh
 TEST_PROGS += sysfs_update_schemes_tried_regions_hang.py
 
+EXTRA_CLEAN = __pycache__
+
 include ../lib.mk
Signature · 1 line
2.39.2
author maintainer
#3 lore raw

PATCH 3/9 selftests/damon: add execute permissions to test scripts

In reply to SeongJae Park

Some test scripts are missing executable permissions. It causes warnings that make the test output unnecessarily verbose. Add executable permissions.

---
Andrew, please note that this patch is for adding the execution permission to the files. I guess these need a special handling for your tooling.

 tools/testing/selftests/damon/damon_nr_regions.py                 | 0
 tools/testing/selftests/damon/damos_apply_interval.py             | 0
 tools/testing/selftests/damon/damos_quota.py                      | 0
 tools/testing/selftests/damon/damos_quota_goal.py                 | 0
 tools/testing/selftests/damon/damos_tried_regions.py              | 0
 tools/testing/selftests/damon/debugfs_target_ids_pid_leak.sh      | 0
 .../damon/debugfs_target_ids_read_before_terminate_race.sh        | 0
 .../selftests/damon/sysfs_update_schemes_tried_regions_hang.py    | 0
 .../damon/sysfs_update_schemes_tried_regions_wss_estimation.py    | 0
 9 files changed, 0 insertions(+), 0 deletions(-)
 mode change 100644 => 100755 tools/testing/selftests/damon/damon_nr_regions.py
 mode change 100644 => 100755 tools/testing/selftests/damon/damos_apply_interval.py
 mode change 100644 => 100755 tools/testing/selftests/damon/damos_quota.py
 mode change 100644 => 100755 tools/testing/selftests/damon/damos_quota_goal.py
 mode change 100644 => 100755 tools/testing/selftests/damon/damos_tried_regions.py
 mode change 100644 => 100755 tools/testing/selftests/damon/debugfs_target_ids_pid_leak.sh
 mode change 100644 => 100755 tools/testing/selftests/damon/debugfs_target_ids_read_before_terminate_race.sh
 mode change 100644 => 100755 tools/testing/selftests/damon/sysfs_update_schemes_tried_regions_hang.py
 mode change 100644 => 100755 tools/testing/selftests/damon/sysfs_update_schemes_tried_regions_wss_estimation.py
tools/testing/selftests/damon/damon_nr_regions.py +0 -0
old mode 100644
new mode 100755
tools/testing/selftests/damon/damos_apply_interval.py +0 -0
old mode 100644
new mode 100755
tools/testing/selftests/damon/damos_quota.py +0 -0
old mode 100644
new mode 100755
tools/testing/selftests/damon/damos_quota_goal.py +0 -0
old mode 100644
new mode 100755
tools/testing/selftests/damon/damos_tried_regions.py +0 -0
old mode 100644
new mode 100755
tools/testing/selftests/damon/debugfs_target_ids_pid_leak.sh +0 -0
old mode 100644
new mode 100755
tools/testing/selftests/damon/debugfs_target_ids_read_before_terminate_race.sh +0 -0
old mode 100644
new mode 100755
tools/testing/selftests/damon/sysfs_update_schemes_tried_regions_hang.py +0 -0
old mode 100644
new mode 100755
tools/testing/selftests/damon/sysfs_update_schemes_tried_regions_wss_estimation.py +0 -0
old mode 100644
new mode 100755
Signature · 1 line
2.39.2
author maintainer
#4 lore raw

PATCH 4/9 mm/damon/core-test: test only vaddr case on ops registration test

In reply to SeongJae Park

DAMON ops registration kunit test tests both vaddr and paddr use cases in parts of the whole test cases. Basically testing only one ops use case is enough. Do the test with only vaddr use case.

---
 mm/damon/core-test.h | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
mm/damon/core-test.h +2 -6
index 0cee634f3544..ef36d586d6ee 100644
@@ -246,16 +246,12 @@ static void damon_test_split_regions_of(struct kunit *test)
 static void damon_test_ops_registration(struct kunit *test)
 {
 	struct damon_ctx *c = damon_new_ctx();
-	struct damon_operations ops, bak;
+	struct damon_operations ops = {.id = DAMON_OPS_VADDR}, bak;
 
-	/* DAMON_OPS_{V,P}ADDR are registered on subsys_initcall */
+	/* DAMON_OPS_VADDR is registered on subsys_initcall */
 	KUNIT_EXPECT_EQ(test, damon_select_ops(c, DAMON_OPS_VADDR), 0);
-	KUNIT_EXPECT_EQ(test, damon_select_ops(c, DAMON_OPS_PADDR), 0);
 
 	/* Double-registration is prohibited */
-	ops.id = DAMON_OPS_VADDR;
-	KUNIT_EXPECT_EQ(test, damon_register_ops(&ops), -EINVAL);
-	ops.id = DAMON_OPS_PADDR;
 	KUNIT_EXPECT_EQ(test, damon_register_ops(&ops), -EINVAL);
 
 	/* Unknown ops id cannot be registered */
Signature · 1 line
2.39.2
author maintainer
#5 lore raw

PATCH 5/9 mm/damon/core-test: fix damon_test_ops_registration() for DAMON_VADDR unset case

In reply to SeongJae Park

DAMON core kunit test can be executed without CONFIG_DAMON_VADDR. In the case, vaddr DAMON ops is not registered. Meanwhile, ops registration kunit test assumes the vaddr ops is registered. Check and handle the case by registrering fake vaddr ops inside the test code.

Fixes 4f540f5ab4f2 ("mm/damon/core-test: add a kunit test case for ops registration")
---
 mm/damon/core-test.h | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
mm/damon/core-test.h +16 -1
index ef36d586d6ee..ae03df71737e 100644
@@ -247,8 +247,16 @@ static void damon_test_ops_registration(struct kunit *test)
 {
 	struct damon_ctx *c = damon_new_ctx();
 	struct damon_operations ops = {.id = DAMON_OPS_VADDR}, bak;
+	bool need_cleanup = false;
 
-	/* DAMON_OPS_VADDR is registered on subsys_initcall */
+	/* DAMON_OPS_VADDR is registered only if CONFIG_DAMON_VADDR is set */
+	if (!damon_is_registered_ops(DAMON_OPS_VADDR)) {
+		bak.id = DAMON_OPS_VADDR;
+		KUNIT_EXPECT_EQ(test, damon_register_ops(&bak), 0);
+		need_cleanup = true;
+	}
+
+	/* DAMON_OPS_VADDR is ensured to be registered */
 	KUNIT_EXPECT_EQ(test, damon_select_ops(c, DAMON_OPS_VADDR), 0);
 
 	/* Double-registration is prohibited */
@@ -274,6 +282,13 @@ static void damon_test_ops_registration(struct kunit *test)
 	KUNIT_EXPECT_EQ(test, damon_register_ops(&ops), -EINVAL);
 
 	damon_destroy_ctx(c);
+
+	if (need_cleanup) {
+		mutex_lock(&damon_ops_lock);
+		damon_registered_ops[DAMON_OPS_VADDR] =
+			(struct damon_operations){};
+		mutex_unlock(&damon_ops_lock);
+	}
 }
 
 static void damon_test_set_regions(struct kunit *test)
Signature · 1 line
2.39.2
author maintainer
#6 lore raw

PATCH 6/9 mm/damon/dbgfs-test: skip dbgfs_set_targets() test if PADDR is not registered

In reply to SeongJae Park

The test depends on registration of DAMON_OPS_PADDR. It would be registered only when CONFIG_DAMON_PADDR is set. DAMON core kunit tests do fake ops registration for such case. However, the functions for such fake ops registration is not available to DAMON debugfs interface. Just skip the test in the case.

Fixes 999b9467974f ("mm/damon/dbgfs-test: fix is_target_id() change")
---
 mm/damon/dbgfs-test.h | 5 +++++
 1 file changed, 5 insertions(+)
mm/damon/dbgfs-test.h +5 -0
index 2d85217f5ba4..9bd5dca5d4ad 100644
@@ -73,6 +73,11 @@ static void damon_dbgfs_test_set_targets(struct kunit *test)
 	struct damon_ctx *ctx = dbgfs_new_ctx();
 	char buf[64];
 
+	if (!damon_is_registered_ops(DAMON_OPS_PADDR)) {
+		dbgfs_destroy_ctx(ctx);
+		kunit_skip(test, "PADDR not registered");
+	}
+
 	/* Make DAMON consider target has no pid */
 	damon_select_ops(ctx, DAMON_OPS_PADDR);
 
Signature · 1 line
2.39.2
author maintainer
#7 lore raw

PATCH 7/9 mm/damon/dbgfs-test: skip dbgfs_set_init_regions() test if PADDR is not registered

In reply to SeongJae Park

The test depends on registration of DAMON_OPS_PADDR. It would be registered only when CONFIG_DAMON_PADDR is set. DAMON core kunit tests do fake ops registration for such case. However, the functions for such fake ops registration is not available to DAMON debugfs interface. Just skip the test in the case.

Fixes 999b9467974f ("mm/damon/dbgfs-test: fix is_target_id() change")
---
 mm/damon/dbgfs-test.h | 5 +++++
 1 file changed, 5 insertions(+)
mm/damon/dbgfs-test.h +5 -0
index 9bd5dca5d4ad..d2ecfcc8db86 100644
@@ -116,6 +116,11 @@ static void damon_dbgfs_test_set_init_regions(struct kunit *test)
 	int i, rc;
 	char buf[256];
 
+	if (!damon_is_registered_ops(DAMON_OPS_PADDR)) {
+		damon_destroy_ctx(ctx);
+		kunit_skip(test, "PADDR not registered");
+	}
+
 	damon_select_ops(ctx, DAMON_OPS_PADDR);
 
 	dbgfs_set_targets(ctx, 3, NULL);
Signature · 1 line
2.39.2
author maintainer
#8 lore raw

PATCH 8/9 mm/damon: move kunit tests to tests/ subdirectory with _kunit suffix

In reply to SeongJae Park

There was a discussion about better places for kunit test code[1] and test file name suffix[2]. Folowwing the conclusion, move kunit tests for DAMON to mm/damon/tests/ subdirectory and rename those.

[1] https://lore.kernel.org/CABVgOS=pUdWb6NDHszuwb1HYws4a1-b1UmN=i8U_ED7HbDT0mg@mail.gmail.com
[2] https://lore.kernel.org/CABVgOSmKwPq7JEpHfS6sbOwsR0B-DBDk_JP-ZD9s9ZizvpUjbQ@mail.gmail.com

---
 mm/damon/core.c                                | 2 +-
 mm/damon/dbgfs.c                               | 2 +-
 mm/damon/sysfs.c                               | 2 +-
 mm/damon/{core-test.h => tests/core-kunit.h}   | 0
 mm/damon/{dbgfs-test.h => tests/dbgfs-kunit.h} | 0
 mm/damon/{sysfs-test.h => tests/sysfs-kunit.h} | 0
 mm/damon/{vaddr-test.h => tests/vaddr-kunit.h} | 0
 mm/damon/vaddr.c                               | 2 +-
 8 files changed, 4 insertions(+), 4 deletions(-)
 rename mm/damon/{core-test.h => tests/core-kunit.h} (100%)
 rename mm/damon/{dbgfs-test.h => tests/dbgfs-kunit.h} (100%)
 rename mm/damon/{sysfs-test.h => tests/sysfs-kunit.h} (100%)
 rename mm/damon/{vaddr-test.h => tests/vaddr-kunit.h} (100%)
mm/damon/core.c +1 -1
index a1c32becfc73..1d2c4daef157 100644
@@ -2275,4 +2275,4 @@ static int __init damon_init(void)
 
 subsys_initcall(damon_init);
 
-#include "core-test.h"
+#include "tests/core-kunit.h"
mm/damon/dbgfs.c +1 -1
index 51a6f1cac385..b4213bc47e44 100644
@@ -1145,4 +1145,4 @@ static int __init damon_dbgfs_init(void)
 
 module_init(damon_dbgfs_init);
 
-#include "dbgfs-test.h"
+#include "tests/dbgfs-kunit.h"
mm/damon/sysfs.c +1 -1
index ecf0835e34b8..4daac92be30b 100644
@@ -1908,4 +1908,4 @@ static int __init damon_sysfs_init(void)
 }
 subsys_initcall(damon_sysfs_init);
 
-#include "sysfs-test.h"
+#include "tests/sysfs-kunit.h"
mm/damon/tests/core-kunit.h renamed from mm/damon/core-test.h +0 -0
similarity index 100%
rename from mm/damon/core-test.h
rename to mm/damon/tests/core-kunit.h
mm/damon/tests/dbgfs-kunit.h renamed from mm/damon/dbgfs-test.h +0 -0
similarity index 100%
rename from mm/damon/dbgfs-test.h
rename to mm/damon/tests/dbgfs-kunit.h
mm/damon/tests/sysfs-kunit.h renamed from mm/damon/sysfs-test.h +0 -0
similarity index 100%
rename from mm/damon/sysfs-test.h
rename to mm/damon/tests/sysfs-kunit.h
mm/damon/tests/vaddr-kunit.h renamed from mm/damon/vaddr-test.h +0 -0
similarity index 100%
rename from mm/damon/vaddr-test.h
rename to mm/damon/tests/vaddr-kunit.h
mm/damon/vaddr.c +1 -1
index 58829baf8b5d..b0e8b361891d 100644
@@ -730,4 +730,4 @@ static int __init damon_va_initcall(void)
 
 subsys_initcall(damon_va_initcall);
 
-#include "vaddr-test.h"
+#include "tests/vaddr-kunit.h"
Signature · 1 line
2.39.2
author maintainer
#9 lore raw

PATCH 9/9 mm/damon/tests: add .kunitconfig file for DAMON kunit tests

In reply to SeongJae Park

'--kunitconfig' option of 'kunit.py run' supports '.kunitconfig' file name convention. Add the file for DAMON kunit tests for more convenient kunit run.

---
 mm/damon/tests/.kunitconfig | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
 create mode 100644 mm/damon/tests/.kunitconfig
mm/damon/tests/.kunitconfig new file +22 -0
new file mode 100644
index 000000000000..a73be044fc9b
@@ -0,0 +1,22 @@
+# for DAMON core
+CONFIG_KUNIT=y
+CONFIG_DAMON=y
+CONFIG_DAMON_KUNIT_TEST=y
+
+# for DAMON vaddr ops
+CONFIG_MMU=y
+CONFIG_PAGE_IDLE_FLAG=y
+CONFIG_DAMON_VADDR=y
+CONFIG_DAMON_VADDR_KUNIT_TEST=y
+
+# for DAMON sysfs interface
+CONFIG_SYSFS=y
+CONFIG_DAMON_SYSFS=y
+CONFIG_DAMON_SYSFS_KUNIT_TEST=y
+
+# for DAMON debugfs interface
+CONFIG_DEBUG_FS=y
+CONFIG_DAMON_PADDR=y
+CONFIG_DAMON_DBGFS_DEPRECATED=y
+CONFIG_DAMON_DBGFS=y
+CONFIG_DAMON_DBGFS_KUNIT_TEST=y
Signature · 1 line
2.39.2