selftests/damon: introduce _common.sh to host shared function

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>
pull/1311/head
Enze Li 2025-07-18 14:42:17 +08:00 committed by Andrew Morton
parent da5973a0b8
commit 511914506d
5 changed files with 22 additions and 24 deletions

View File

@ -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
}

View File

@ -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" ]

View File

@ -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" ]

View File

@ -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"

View File

@ -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" ]