diff mbox series

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

Message ID 20211110093315.3219191-3-tan.shaopeng@jp.fujitsu.com (mailing list archive)
State New
Headers show
Series selftests/resctrl: Add resctrl_tests into kselftest set | expand

Commit Message

Shaopeng Tan Nov. 10, 2021, 9:33 a.m. UTC
From: "Tan, Shaopeng" <tan.shaopeng@jp.fujitsu.com>

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 <tan.shaopeng@jp.fujitsu.com>
---
 tools/testing/selftests/resctrl/resctrl_tests.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Reinette Chatre Nov. 29, 2021, 7:27 p.m. UTC | #1
Hi Shaopeng Tan,

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

On 11/10/2021 1:33 AM, Shaopeng Tan wrote:
> From: "Tan, Shaopeng" <tan.shaopeng@jp.fujitsu.com>
> 
> 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
Shaopeng Tan (Fujitsu) Dec. 1, 2021, 2:36 a.m. UTC | #2
Hi Reinette
 
> (subject line and commit message: filessystem -> file system)
Thanks.
 
> On 11/10/2021 1:33 AM, Shaopeng Tan wrote:
> > From: "Tan, Shaopeng" <tan.shaopeng@jp.fujitsu.com>
> >
> > 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
Reinette Chatre Dec. 2, 2021, 12:39 a.m. UTC | #3
Hi Shaopeng Tan,

On 11/30/2021 6:36 PM, tan.shaopeng@fujitsu.com 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" <tan.shaopeng@jp.fujitsu.com>
>>>
>>> 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
diff mbox series

Patch

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();