From 96f3bacc93df4074b0e9712a547dd5271da5c4fc Mon Sep 17 00:00:00 2001 From: Petre Tudor Date: Wed, 29 Jan 2025 17:05:18 +0000 Subject: [PATCH] chrt: (tests) Add new cases for custom slice on SCHED_{OTHER,BATCH} Adds two new test cases setting --sched-runtime for SCHED_{OTHER,BATCH}. The new custom slice tests are skipped for kernel versions < 6.12, which do not have the feature. The existing chrt tests for SCHED_{OTHER,BATCH} are skipped for kernel versions >= 6.12. This is for two reasons: - the default sched_runtime value depends on target platform - without custom slice support, the value of sched_runtime is always zero for SCHED_{OTHER,BATCH} Expected output with kernel version < 6.12: schedutils: chrt ... : batch ... OK : batch-custom-slice ... SKIPPED : other ... OK : other-custom-slice ... SKIPPED : deadline ... OK Expected output with kernel version >= 6.12: schedutils: chrt ... : batch ... SKIPPED : batch-custom-slice ... OK : other ... SKIPPED : other-custom-slice ... OK : deadline ... OK Signed-off-by: Petre Tudor --- .../schedutils/chrt-batch-custom-slice | 3 ++ .../schedutils/chrt-other-custom-slice | 3 ++ tests/functions.sh | 28 ++++++++++++- tests/ts/schedutils/chrt | 42 ++++++++++++++++++- 4 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 tests/expected/schedutils/chrt-batch-custom-slice create mode 100644 tests/expected/schedutils/chrt-other-custom-slice diff --git a/tests/expected/schedutils/chrt-batch-custom-slice b/tests/expected/schedutils/chrt-batch-custom-slice new file mode 100644 index 00000000000..ea788bfb4d0 --- /dev/null +++ b/tests/expected/schedutils/chrt-batch-custom-slice @@ -0,0 +1,3 @@ +SCHED_BATCH +0 +'s current runtime parameter: 100000 diff --git a/tests/expected/schedutils/chrt-other-custom-slice b/tests/expected/schedutils/chrt-other-custom-slice new file mode 100644 index 00000000000..df1db194c99 --- /dev/null +++ b/tests/expected/schedutils/chrt-other-custom-slice @@ -0,0 +1,3 @@ +SCHED_OTHER +0 +'s current runtime parameter: 100000 diff --git a/tests/functions.sh b/tests/functions.sh index d5a92c91c80..1d7a425f692 100644 --- a/tests/functions.sh +++ b/tests/functions.sh @@ -312,8 +312,13 @@ function ts_init_env { CHARSET="UTF-8" ASAN_OPTIONS="detect_leaks=0" UBSAN_OPTIONS="print_stacktrace=1:print_summary=1:halt_on_error=1" + KERNEL_VERSION_XYZ=$(uname -r | awk -F- '{print $1}') + KERNEL_VERSION_MAJOR=$(echo "$KERNEL_VERSION_XYZ" | awk -F. '{print $1}') + KERNEL_VERSION_MINOR=$(echo "$KERNEL_VERSION_XYZ" | awk -F. '{print $2}') + KERNEL_RELEASE=$(echo "$KERNEL_VERSION_XYZ" | awk -F. '{print $3}') - export LANG LANGUAGE LC_ALL CHARSET ASAN_OPTIONS UBSAN_OPTIONS + export LANG LANGUAGE LC_ALL CHARSET ASAN_OPTIONS UBSAN_OPTIONS \ + KERNEL_VERSION_XYZ KERNEL_VERSION_MAJOR KERNEL_VERSION_MINOR KERNEL_RELEASE mydir=$(ts_canonicalize "$mydir") @@ -641,6 +646,27 @@ function ts_skip_subtest { } +# Specify the kernel version X.Y.Z you wish to compare against like: +# +# ts_kernel_ver_lt X Y Z +# +function ts_kernel_ver_lt { + if [ $KERNEL_VERSION_MAJOR -lt $1 ]; then + return 0 + elif [ $KERNEL_VERSION_MAJOR -eq $1 ]; then + if [ $KERNEL_VERSION_MINOR -lt $2 ]; then + return 0 + elif [ $KERNEL_VERSION_MINOR -eq $2 ]; then + if [ $KERNEL_RELEASE -lt $3 ]; then + return 0 + fi + fi + + fi + + return 1 +} + function ts_finalize { ts_cleanup_on_exit diff --git a/tests/ts/schedutils/chrt b/tests/ts/schedutils/chrt index fd5f7af781f..74186c05347 100755 --- a/tests/ts/schedutils/chrt +++ b/tests/ts/schedutils/chrt @@ -37,6 +37,26 @@ function skip_policy { return 0 } +function skip_kernel_lt { + ts_kernel_ver_lt $1 $2 $3 + if [ $? == 0 ]; then + ts_skip_subtest "kernel version must be >= $1.$2.$3" + return 1 + fi + + return 0 +} + +function skip_kernel_ge { + ts_kernel_ver_lt $1 $2 $3 + if [ $? == 1 ]; then + ts_skip_subtest "kernel version must be < $1.$2.$3" + return 1 + fi + + return 0 +} + function cleanup_output { sed -i -e 's/pid [0-9]*//' $TS_OUTPUT } @@ -53,7 +73,7 @@ fi ts_init_subtest "batch" -skip_policy SCHED_BATCH +skip_policy SCHED_BATCH && skip_kernel_ge 6 12 0 if [ $? == 0 ]; then do_chrt --batch 0 cleanup_output @@ -61,8 +81,17 @@ if [ $? == 0 ]; then fi +ts_init_subtest "batch-custom-slice" +skip_policy SCHED_BATCH && skip_kernel_lt 6 12 0 +if [ $? == 0 ]; then + do_chrt --batch --sched-runtime 100000 0 + cleanup_output + ts_finalize_subtest +fi + + ts_init_subtest "other" -skip_policy SCHED_OTHER +skip_policy SCHED_OTHER && skip_kernel_ge 6 12 0 if [ $? == 0 ]; then do_chrt --other 0 cleanup_output @@ -70,6 +99,15 @@ if [ $? == 0 ]; then fi +ts_init_subtest "other-custom-slice" +skip_policy SCHED_OTHER && skip_kernel_lt 6 12 0 +if [ $? == 0 ]; then + do_chrt --other --sched-runtime 100000 0 + cleanup_output + ts_finalize_subtest +fi + + ts_init_subtest "rr" skip_policy SCHED_RR if [ $? == 0 ]; then