]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftests/damon: introduce _common.sh to host shared function
authorEnze Li <lienze@kylinos.cn>
Fri, 18 Jul 2025 06:42:17 +0000 (14:42 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Sat, 26 Jul 2025 22:08:21 +0000 (15:08 -0700)
The current test scripts contain duplicated root permission checks in
multiple locations.  This patch consolidates these checks into _common.sh
to eliminate code redundancy.

Link: https://lkml.kernel.org/r/20250718064217.299300-1-lienze@kylinos.cn
Signed-off-by: Enze Li <lienze@kylinos.cn>
Reviewed-by: SeongJae Park <sj@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
tools/testing/selftests/damon/_common.sh [new file with mode: 0644]
tools/testing/selftests/damon/lru_sort.sh
tools/testing/selftests/damon/reclaim.sh
tools/testing/selftests/damon/sysfs.sh
tools/testing/selftests/damon/sysfs_update_removed_scheme_dir.sh

diff --git a/tools/testing/selftests/damon/_common.sh b/tools/testing/selftests/damon/_common.sh
new file mode 100644 (file)
index 0000000..0279698
--- /dev/null
@@ -0,0 +1,11 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+check_dependencies()
+{
+       if [ $EUID -ne 0 ]
+       then
+               echo "Run as root"
+               exit $ksft_skip
+       fi
+}
index 61b80197c89660cffb3db9d345a8aa6995a9853d..1e4849db78a919702dfbac751069c185cbc5eb22 100755 (executable)
@@ -1,14 +1,12 @@
 #!/bin/bash
 # SPDX-License-Identifier: GPL-2.0
 
+source _common.sh
+
 # Kselftest framework requirement - SKIP code is 4.
 ksft_skip=4
 
-if [ $EUID -ne 0 ]
-then
-       echo "Run as root"
-       exit $ksft_skip
-fi
+check_dependencies
 
 damon_lru_sort_enabled="/sys/module/damon_lru_sort/parameters/enabled"
 if [ ! -f "$damon_lru_sort_enabled" ]
index 78dbc2334cbe123cbf5df50085c68a681a43cbe0..e56ceb03512998f0dc7f15c1989ba6ba87f31f3a 100755 (executable)
@@ -1,14 +1,12 @@
 #!/bin/bash
 # SPDX-License-Identifier: GPL-2.0
 
+source _common.sh
+
 # Kselftest framework requirement - SKIP code is 4.
 ksft_skip=4
 
-if [ $EUID -ne 0 ]
-then
-       echo "Run as root"
-       exit $ksft_skip
-fi
+check_dependencies
 
 damon_reclaim_enabled="/sys/module/damon_reclaim/parameters/enabled"
 if [ ! -f "$damon_reclaim_enabled" ]
index e9a976d296e210460fac6494ced933753d18ca16..83e3b7f63d81cf3654b966403c62b0a7bde96778 100755 (executable)
@@ -1,6 +1,8 @@
 #!/bin/bash
 # SPDX-License-Identifier: GPL-2.0
 
+source _common.sh
+
 # Kselftest frmework requirement - SKIP code is 4.
 ksft_skip=4
 
@@ -364,14 +366,5 @@ test_damon_sysfs()
        test_kdamonds "$damon_sysfs/kdamonds"
 }
 
-check_dependencies()
-{
-       if [ $EUID -ne 0 ]
-       then
-               echo "Run as root"
-               exit $ksft_skip
-       fi
-}
-
 check_dependencies
 test_damon_sysfs "/sys/kernel/mm/damon/admin"
index ade35576e748760f61a791b4356660f683b83397..35fc32beeaf7ccb7002821cd1755de1ef7f304a6 100755 (executable)
@@ -1,14 +1,12 @@
 #!/bin/bash
 # SPDX-License-Identifier: GPL-2.0
 
+source _common.sh
+
 # Kselftest framework requirement - SKIP code is 4.
 ksft_skip=4
 
-if [ $EUID -ne 0 ]
-then
-       echo "Run as root"
-       exit $ksft_skip
-fi
+check_dependencies
 
 damon_sysfs="/sys/kernel/mm/damon/admin"
 if [ ! -d "$damon_sysfs" ]