Skip to content

Commit 5119145

Browse files
lienzeakpm00
authored andcommitted
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/[email protected] Signed-off-by: Enze Li <[email protected]> Reviewed-by: SeongJae Park <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent da5973a commit 5119145

File tree

5 files changed

+22
-24
lines changed

5 files changed

+22
-24
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
4+
check_dependencies()
5+
{
6+
if [ $EUID -ne 0 ]
7+
then
8+
echo "Run as root"
9+
exit $ksft_skip
10+
fi
11+
}

tools/testing/selftests/damon/lru_sort.sh

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
#!/bin/bash
22
# SPDX-License-Identifier: GPL-2.0
33

4+
source _common.sh
5+
46
# Kselftest framework requirement - SKIP code is 4.
57
ksft_skip=4
68

7-
if [ $EUID -ne 0 ]
8-
then
9-
echo "Run as root"
10-
exit $ksft_skip
11-
fi
9+
check_dependencies
1210

1311
damon_lru_sort_enabled="/sys/module/damon_lru_sort/parameters/enabled"
1412
if [ ! -f "$damon_lru_sort_enabled" ]

tools/testing/selftests/damon/reclaim.sh

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
#!/bin/bash
22
# SPDX-License-Identifier: GPL-2.0
33

4+
source _common.sh
5+
46
# Kselftest framework requirement - SKIP code is 4.
57
ksft_skip=4
68

7-
if [ $EUID -ne 0 ]
8-
then
9-
echo "Run as root"
10-
exit $ksft_skip
11-
fi
9+
check_dependencies
1210

1311
damon_reclaim_enabled="/sys/module/damon_reclaim/parameters/enabled"
1412
if [ ! -f "$damon_reclaim_enabled" ]

tools/testing/selftests/damon/sysfs.sh

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/bash
22
# SPDX-License-Identifier: GPL-2.0
33

4+
source _common.sh
5+
46
# Kselftest frmework requirement - SKIP code is 4.
57
ksft_skip=4
68

@@ -364,14 +366,5 @@ test_damon_sysfs()
364366
test_kdamonds "$damon_sysfs/kdamonds"
365367
}
366368

367-
check_dependencies()
368-
{
369-
if [ $EUID -ne 0 ]
370-
then
371-
echo "Run as root"
372-
exit $ksft_skip
373-
fi
374-
}
375-
376369
check_dependencies
377370
test_damon_sysfs "/sys/kernel/mm/damon/admin"

tools/testing/selftests/damon/sysfs_update_removed_scheme_dir.sh

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
#!/bin/bash
22
# SPDX-License-Identifier: GPL-2.0
33

4+
source _common.sh
5+
46
# Kselftest framework requirement - SKIP code is 4.
57
ksft_skip=4
68

7-
if [ $EUID -ne 0 ]
8-
then
9-
echo "Run as root"
10-
exit $ksft_skip
11-
fi
9+
check_dependencies
1210

1311
damon_sysfs="/sys/kernel/mm/damon/admin"
1412
if [ ! -d "$damon_sysfs" ]

0 commit comments

Comments
 (0)