2022-11-18 11:21:49

by Kamalesh Babulal

[permalink] [raw]
Subject: [PATCH] kselftest/cgroup: Add cleanup() to test_cpuset_prs.sh

Install a cleanup function using the trap command for signals EXIT,
SIGINT, SIGQUIT and SIGABRT. The cleanup function will perform:
1. Online the CPUs that were made offline during the test.
2. Removing the cgroups created.
3. Restoring the original /sys/kernel/debug/sched/verbose value,
currently it's left turned on, irrespective of the original
configuration value.

the test performs steps 1 and 2, on the successful runs, but not during
all of the failed runs. With the cleanup(), the system will perform all
three steps during failed/passed test runs.

Signed-off-by: Kamalesh Babulal <[email protected]>
---
.../testing/selftests/cgroup/test_cpuset_prs.sh | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/cgroup/test_cpuset_prs.sh b/tools/testing/selftests/cgroup/test_cpuset_prs.sh
index 526d2c42d870..b8ed82b55b1d 100755
--- a/tools/testing/selftests/cgroup/test_cpuset_prs.sh
+++ b/tools/testing/selftests/cgroup/test_cpuset_prs.sh
@@ -16,7 +16,12 @@ skip_test() {
[[ $(id -u) -eq 0 ]] || skip_test "Test must be run as root!"

# Set sched verbose flag, if available
-[[ -d /sys/kernel/debug/sched ]] && echo Y > /sys/kernel/debug/sched/verbose
+if [[ -d /sys/kernel/debug/sched ]]
+then
+ # Used to restore the original setting during cleanup
+ SCHED_DEBUG=$(cat /sys/kernel/debug/sched/verbose)
+ echo Y > /sys/kernel/debug/sched/verbose
+fi

# Get wait_inotify location
WAIT_INOTIFY=$(cd $(dirname $0); pwd)/wait_inotify
@@ -54,6 +59,15 @@ echo +cpuset > cgroup.subtree_control
[[ -d test ]] || mkdir test
cd test

+cleanup()
+{
+ online_cpus
+ rmdir A1/A2/A3 A1/A2 A1 B1 > /dev/null 2>&1
+ cd ..
+ rmdir test > /dev/null 2>&1
+ echo "$SCHED_DEBUG" > /sys/kernel/debug/sched/verbose
+}
+
# Pause in ms
pause()
{
@@ -666,6 +680,7 @@ test_inotify()
fi
}

+trap cleanup 0 2 3 6
run_state_test TEST_MATRIX
test_isolated
test_inotify
--
2.34.3



2022-11-18 21:33:40

by Waiman Long

[permalink] [raw]
Subject: Re: [PATCH] kselftest/cgroup: Add cleanup() to test_cpuset_prs.sh

On 11/18/22 05:13, Kamalesh Babulal wrote:
> Install a cleanup function using the trap command for signals EXIT,
> SIGINT, SIGQUIT and SIGABRT. The cleanup function will perform:
> 1. Online the CPUs that were made offline during the test.
> 2. Removing the cgroups created.
> 3. Restoring the original /sys/kernel/debug/sched/verbose value,
> currently it's left turned on, irrespective of the original
> configuration value.
>
> the test performs steps 1 and 2, on the successful runs, but not during
> all of the failed runs. With the cleanup(), the system will perform all
> three steps during failed/passed test runs.
>
> Signed-off-by: Kamalesh Babulal <[email protected]>
> ---
> .../testing/selftests/cgroup/test_cpuset_prs.sh | 17 ++++++++++++++++-
> 1 file changed, 16 insertions(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/cgroup/test_cpuset_prs.sh b/tools/testing/selftests/cgroup/test_cpuset_prs.sh
> index 526d2c42d870..b8ed82b55b1d 100755
> --- a/tools/testing/selftests/cgroup/test_cpuset_prs.sh
> +++ b/tools/testing/selftests/cgroup/test_cpuset_prs.sh
> @@ -16,7 +16,12 @@ skip_test() {
> [[ $(id -u) -eq 0 ]] || skip_test "Test must be run as root!"
>
> # Set sched verbose flag, if available
> -[[ -d /sys/kernel/debug/sched ]] && echo Y > /sys/kernel/debug/sched/verbose
> +if [[ -d /sys/kernel/debug/sched ]]
> +then
> + # Used to restore the original setting during cleanup
> + SCHED_DEBUG=$(cat /sys/kernel/debug/sched/verbose)
> + echo Y > /sys/kernel/debug/sched/verbose
> +fi
>
> # Get wait_inotify location
> WAIT_INOTIFY=$(cd $(dirname $0); pwd)/wait_inotify
> @@ -54,6 +59,15 @@ echo +cpuset > cgroup.subtree_control
> [[ -d test ]] || mkdir test
> cd test
>
> +cleanup()
> +{
> + online_cpus
> + rmdir A1/A2/A3 A1/A2 A1 B1 > /dev/null 2>&1
> + cd ..
> + rmdir test > /dev/null 2>&1
> + echo "$SCHED_DEBUG" > /sys/kernel/debug/sched/verbose
> +}
> +
> # Pause in ms
> pause()
> {
> @@ -666,6 +680,7 @@ test_inotify()
> fi
> }
>
> +trap cleanup 0 2 3 6
> run_state_test TEST_MATRIX
> test_isolated
> test_inotify

That looks good to me. Thanks for the improvement.

Acked-by: Waiman Long <[email protected]>


2022-11-22 21:19:32

by Tejun Heo

[permalink] [raw]
Subject: Re: [PATCH] kselftest/cgroup: Add cleanup() to test_cpuset_prs.sh

On Fri, Nov 18, 2022 at 03:43:30PM +0530, Kamalesh Babulal wrote:
> Install a cleanup function using the trap command for signals EXIT,
> SIGINT, SIGQUIT and SIGABRT. The cleanup function will perform:
> 1. Online the CPUs that were made offline during the test.
> 2. Removing the cgroups created.
> 3. Restoring the original /sys/kernel/debug/sched/verbose value,
> currently it's left turned on, irrespective of the original
> configuration value.
>
> the test performs steps 1 and 2, on the successful runs, but not during
> all of the failed runs. With the cleanup(), the system will perform all
> three steps during failed/passed test runs.
>
> Signed-off-by: Kamalesh Babulal <[email protected]>

Applied cgroup/for-6.2.

Thanks.

--
tejun