Hi Reinette, Ilpo,

On Fri, Jun 27, 2025, Reinette Chatre wrote:
> I agree that the test self will know best what went wrong. Tests can still
> use ksft_print_msg() for informational text.
>
> Doing something like:
>
>       cat_ctrlgrp_msr_test() {
>               ...
>               if (!msr_access_supported(uparams->cpu)) {
>                       ksft_print_msg("MSR access not supported\n");
>                       return KSFT_SKIP;
>               ...
>       }
>
>
>       run_single_test() {
>               ...
>               ret = test->run_test(test, uparams);
>               ksft_test_result_report(ret, "%s: test\n", test->name);
>               ...
>       }
>
> Can result in output like:
> # MSR access not supported
> ok X SKIP CAT_GROUP_MASK: test
>
> As I understand this will keep accurate test counts and the user output
> seems intuitive enough to understand why a test may have been skipped.

I suppose what you are suggesting is like below. I did a test with this
adjustment applied on top of this patch set, and it works for me:

[root@dmr-301 chenyu]# ./resctrl_tests -t CAT_GROUP_TASKS
TAP version 13
# Pass: Check kernel supports resctrl filesystem
# Pass: Check resctrl mountpoint "/sys/fs/resctrl" exists
# resctrl filesystem not mounted
# dmesg: [   43.705792] resctrl: L3 allocation detected
# dmesg: [   43.712878] resctrl: L2 allocation detected
# dmesg: [   43.719856] resctrl: MB allocation detected
# dmesg: [   43.726800] resctrl: L3 monitoring detected
1..1
# Starting CAT_GROUP_TASKS test ...
# Mounting resctrl to "/sys/fs/resctrl"
# Writing benchmark parameters to resctrl FS
# Writing benchmark parameters to resctrl FS
ok 1 CAT_GROUP_TASKS: test
# Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0

[root@dmr-301 chenyu]# ./resctrl_tests -t CAT_GROUP_MASK
TAP version 13
# Pass: Check kernel supports resctrl filesystem
# Pass: Check resctrl mountpoint "/sys/fs/resctrl" exists
# resctrl filesystem not mounted
# dmesg: [   43.705792] resctrl: L3 allocation detected
# dmesg: [   43.712878] resctrl: L2 allocation detected
# dmesg: [   43.719856] resctrl: MB allocation detected
# dmesg: [   43.726800] resctrl: L3 monitoring detected
1..1
# Starting CAT_GROUP_MASK test ...
# Mounting resctrl to "/sys/fs/resctrl"
# Placing task to ctrlgrp 'c1'
# Writing benchmark parameters to resctrl FS
# Write schema "L3:0=3" to resctrl FS
# Placing task to ctrlgrp 'c2'
# Writing benchmark parameters to resctrl FS
# Write schema "L3:0=6" to resctrl FS
# Adjusting CBM for unrelated ctrlgrp 'c1'
# Write schema "L3:0=c" to resctrl FS
# Adjusting CBM for ctrlgrp 'c2'
# Write schema "L3:0=3" to resctrl FS
# Placing task to ctrlgrp 'c1'
# Writing benchmark parameters to resctrl FS
ok 1 CAT_GROUP_MASK: test
# Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0

---
diff --git a/tools/testing/selftests/resctrl/cat_test.c 
b/tools/testing/selftests/resctrl/cat_test.c
index 76791312da76..5718ecf3b35d 100644
--- a/tools/testing/selftests/resctrl/cat_test.c
+++ b/tools/testing/selftests/resctrl/cat_test.c
@@ -399,7 +399,7 @@ static int cat_ctrlgrp_tasks_test(const struct resctrl_test 
*test,
                return ret;
        if (!ret) {
                ksft_print_msg("PID not found in the root group\n");
-               return 1;
+               return KSFT_FAIL;
        }
 
        /* Taskset benchmark to specified CPU */
@@ -411,7 +411,7 @@ static int cat_ctrlgrp_tasks_test(const struct resctrl_test 
*test,
                goto reset_affinity;
        if (!ret) {
                ksft_print_msg("PID not found in the root group\n");
-               ret = 1;
+               ret = KSFT_FAIL;
                goto reset_affinity;
        }
 
@@ -423,7 +423,7 @@ static int cat_ctrlgrp_tasks_test(const struct resctrl_test 
*test,
                goto reset_affinity;
        if (!ret) {
                ksft_print_msg("PID not found in the control group\n");
-               ret = 1;
+               ret = KSFT_FAIL;
                goto reset_affinity;
        }
        ret = resctrl_grp_has_task(NULL, bm_pid);
@@ -431,7 +431,7 @@ static int cat_ctrlgrp_tasks_test(const struct resctrl_test 
*test,
                goto reset_affinity;
        if (ret) {
                ksft_print_msg("PID duplicate remains in the root group\n");
-               ret = 1;
+               ret = KSFT_FAIL;
                goto reset_affinity;
        }
 
@@ -443,7 +443,7 @@ static int cat_ctrlgrp_tasks_test(const struct resctrl_test 
*test,
                goto reset_affinity;
        if (!ret) {
                ksft_print_msg("PID not found in the new control group\n");
-               ret = 1;
+               ret = KSFT_FAIL;
                goto reset_affinity;
        }
        ret = resctrl_grp_has_task("c1", bm_pid);
@@ -451,7 +451,7 @@ static int cat_ctrlgrp_tasks_test(const struct resctrl_test 
*test,
                goto reset_affinity;
        if (ret) {
                ksft_print_msg("PID duplicate remains in the old control 
group\n");
-               ret = 1;
+               ret = KSFT_FAIL;
                goto reset_affinity;
        }
 
@@ -499,8 +499,8 @@ static int cat_ctrlgrp_msr_test(const struct resctrl_test 
*test,
        bm_pid = getpid();
 
        if (!msr_access_supported(uparams->cpu)) {
-               ksft_test_result_skip("Cannot access MSRs\n");
-               return 0;
+               ksft_print_msg("MSR access not supported\n");
+               return KSFT_SKIP;
        }
 
        ret = resctrl_grp_has_task(NULL, bm_pid);
@@ -508,7 +508,7 @@ static int cat_ctrlgrp_msr_test(const struct resctrl_test 
*test,
                return ret;
        if (!ret) {
                ksft_print_msg("PID not found in the root group\n");
-               return 1;
+               return KSFT_FAIL;
        }
 
        /* Taskset benchmark to specified CPU */
diff --git a/tools/testing/selftests/resctrl/resctrl_tests.c 
b/tools/testing/selftests/resctrl/resctrl_tests.c
index a0390f045646..6989e1422588 100644
--- a/tools/testing/selftests/resctrl/resctrl_tests.c
+++ b/tools/testing/selftests/resctrl/resctrl_tests.c
@@ -163,7 +163,7 @@ static void run_single_test(const struct resctrl_test 
*test, const struct user_p
        }
 
        ret = test->run_test(test, uparams);
-       ksft_test_result(!ret, "%s: test\n", test->name);
+       ksft_test_result_report(ret, "%s: test\n", test->name);
 
 cleanup:
        test_cleanup(test);

Reply via email to