2021-11-10 09:37:05

by Shaopeng Tan

[permalink] [raw]
Subject: [PATCH 2/3] selftests/resctrl: Return KSFT_SKIP(4) if resctrl filessystem is not supported or resctrl is not run as root

From: "Tan, Shaopeng" <[email protected]>

To unify the return code of resctrl_tests with the return code of
selftest set, return KSFT_SKIP (4) if resctrl filessystem is not
supported or resctrl is not run as root.

Signed-off-by: Shaopeng Tan <[email protected]>
---
tools/testing/selftests/resctrl/resctrl_tests.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/resctrl/resctrl_tests.c b/tools/testing/selftests/resctrl/resctrl_tests.c
index 973f09a..3be0895 100644
--- a/tools/testing/selftests/resctrl/resctrl_tests.c
+++ b/tools/testing/selftests/resctrl/resctrl_tests.c
@@ -205,7 +205,7 @@ int main(int argc, char **argv)
* 2. We execute perf commands
*/
if (geteuid() != 0)
- return ksft_exit_fail_msg("Not running as root, abort testing.\n");
+ return ksft_exit_skip("Not running as root, abort testing.\n");

/* Detect AMD vendor */
detect_amd();
@@ -235,7 +235,7 @@ int main(int argc, char **argv)
sprintf(bm_type, "fill_buf");

if (!check_resctrlfs_support())
- return ksft_exit_fail_msg("resctrl FS does not exist\n");
+ return ksft_exit_skip("resctrl FS does not exist\n");

filter_dmesg();

--
1.8.3.1


2021-11-29 19:30:16

by Reinette Chatre

[permalink] [raw]
Subject: Re: [PATCH 2/3] selftests/resctrl: Return KSFT_SKIP(4) if resctrl filessystem is not supported or resctrl is not run as root

Hi Shaopeng Tan,

(subject line and commit message: filessystem -> file system)

On 11/10/2021 1:33 AM, Shaopeng Tan wrote:
> From: "Tan, Shaopeng" <[email protected]>
>
> To unify the return code of resctrl_tests with the return code of
> selftest set, return KSFT_SKIP (4) if resctrl filessystem is not
> supported or resctrl is not run as root.

Could you please elaborate how changing ksft_exit_fail_msg() to
ksft_exit_skip() accomplishes the goal of unifying the return code?
What is wrong with using ksft_exit_fail_msg()?

Reinette

2021-12-01 02:37:16

by Shaopeng Tan (Fujitsu)

[permalink] [raw]
Subject: RE: [PATCH 2/3] selftests/resctrl: Return KSFT_SKIP(4) if resctrl filessystem is not supported or resctrl is not run as root

Hi Reinette

> (subject line and commit message: filessystem -> file system)
Thanks.

> On 11/10/2021 1:33 AM, Shaopeng Tan wrote:
> > From: "Tan, Shaopeng" <[email protected]>
> >
> > To unify the return code of resctrl_tests with the return code of
> > selftest set, return KSFT_SKIP (4) if resctrl filessystem is not
> > supported or resctrl is not run as root.
>
> Could you please elaborate how changing ksft_exit_fail_msg() to
> ksft_exit_skip() accomplishes the goal of unifying the return code?
> What is wrong with using ksft_exit_fail_msg()?

In selftest framwork,
if a test need root privileges, but it is run as user privileges,
the test result will counted as a SKIP item, instead of a FAIL item.

For example,
(1)tools/testing/selftests/mqueue/mq_open_tests.c
267 if (getuid() != 0)
268 ksft_exit_skip("Not running as root, but almost all tests "
269 "require root in order to modify\nsystem settings. "
270 "Exiting.\n");

(2)tools/testing/selftests/bpf/test_kmod.sh
5 ksft_skip=4
6
7 msg="skip all tests:"
8 if [ "$(id -u)" != "0" ]; then
9 echo $msg please run this as root >&2
10 exit $ksft_skip
11 fi

Regards,
Shaopeng Tan

2021-12-02 00:42:37

by Reinette Chatre

[permalink] [raw]
Subject: Re: [PATCH 2/3] selftests/resctrl: Return KSFT_SKIP(4) if resctrl filessystem is not supported or resctrl is not run as root

Hi Shaopeng Tan,

On 11/30/2021 6:36 PM, [email protected] wrote:
> Hi Reinette
>
>> (subject line and commit message: filessystem -> file system)
> Thanks.
>
>> On 11/10/2021 1:33 AM, Shaopeng Tan wrote:
>>> From: "Tan, Shaopeng" <[email protected]>
>>>
>>> To unify the return code of resctrl_tests with the return code of
>>> selftest set, return KSFT_SKIP (4) if resctrl filessystem is not
>>> supported or resctrl is not run as root.
>>
>> Could you please elaborate how changing ksft_exit_fail_msg() to
>> ksft_exit_skip() accomplishes the goal of unifying the return code?
>> What is wrong with using ksft_exit_fail_msg()?
>
> In selftest framwork,
> if a test need root privileges, but it is run as user privileges,
> the test result will counted as a SKIP item, instead of a FAIL item.

Thank you for the details. I think it is important to highlight that a
skipped test is marked as successful to not unnecessarily report a
feature failure when there actually is a failure in the test environment.

Reinette