All of lore.kernel.org
 help / color / mirror / Atom feed
From: Petr Vorel <pvorel@suse.cz>
To: Cyril Hrubis <chrubis@suse.cz>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH] sched: add sched sysctl sanity test
Date: Fri, 1 Sep 2023 18:15:28 +0200	[thread overview]
Message-ID: <20230901161528.GA364687@pevik> (raw)
In-Reply-To: <20230901144433.2526-1-chrubis@suse.cz>

Hi Cyril,

> Currently the test fails due to kernel bug, I will send patch to LKML
> later on.
+1.

> The problem with kernel is that sysctl_sched_rt_period is unsigned int
> but it's processed with proc_dointvec() which means that you are allowed
> to write negative values into the variable even though documentation
> says it shouldn't be possible and the kernel code asserts that rt_period
> is > 0.

Interesting.

LTP patch uses sometimes spaces instead of tabs:

$ make check-proc_sched_rt01
CHECK testcases/kernel/sched/sysctl/proc_sched_rt01.c
proc_sched_rt01.c:49: ERROR: code indent should use tabs where possible
proc_sched_rt01.c:55: ERROR: code indent should use tabs where possible
proc_sched_rt01.c:57: ERROR: code indent should use tabs where possible
proc_sched_rt01.c:63: ERROR: code indent should use tabs where possible
proc_sched_rt01.c:76: ERROR: code indent should use tabs where possible

...
> diff --git a/testcases/kernel/sched/sysctl/.gitignore b/testcases/kernel/sched/sysctl/.gitignore
> new file mode 100644
> index 000000000..29b859b81
> --- /dev/null
> +++ b/testcases/kernel/sched/sysctl/.gitignore
> @@ -0,0 +1 @@
> +proc_sched_rt01
nit: We usually put / in the front:
/proc_sched_rt01

...
> +++ b/testcases/kernel/sched/sysctl/proc_sched_rt01.c
> @@ -0,0 +1,115 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (C) Cyril Hrubis <chrubis@suse.cz>
> + */
> +
> +/*\
> + * [Description]
> + *
> + * Sanity tests for the /proc/sys/kernel/sched_r* files.
> + *
> + * - The sched_rt_period_us range is 1 to INT_MAX
> + *   try invalid values and check for EINVAL
> + *
> + * - The sched_rt_runtime_us range is -1 to INT_MAX
> + *   try invalid values and check for EINVAL
> + *
> + * - The sched_rt_runtime_us must be less or equal to sched_rt_period_us
> + *
> + * - Reset sched_rr_timeslice_ms to default value by writing -1 and check that
> + *   we get the default value on next read.
very nit: If you use dot at the end of this sentence, please add it also to the
previous sentences.

> + *
> + *   This is a regression test for a commit:
> + *
> + *   commit c1fc6484e1fb7cc2481d169bfef129a1b0676abe
> + *   Author: Cyril Hrubis <chrubis@suse.cz>
> + *   Date:   Wed Aug 2 17:19:06 2023 +0200
> + *
> + *       sched/rt: sysctl_sched_rr_timeslice show default timeslice after reset

nit: this makes docparse formatting ugly. This would be nicer:
c1fc6484e1fb ("sched/rt: sysctl_sched_rr_timeslice show default timeslice after reset")
(Unless we really prefer to have the date in the output, but in that case adding
a note which kernel version was fixing it would be IMHO more informative than
the date.)

> + */
> +
> +#include <stdio.h>
> +#include "tst_test.h"
> +
> +#define RT_PERIOD_US "/proc/sys/kernel/sched_rt_period_us"
> +#define RT_RUNTIME_US "/proc/sys/kernel/sched_rt_runtime_us"
> +#define RR_TIMESLICE_MS "/proc/sys/kernel/sched_rr_timeslice_ms"
> +
> +static int period_fd;
> +static int runtime_fd;
> +
> +static void rr_timeslice_ms_reset(void)
> +{
> +	long timeslice_ms;
> +
> +	SAFE_FILE_PRINTF(RR_TIMESLICE_MS, "-1");
> +	SAFE_FILE_SCANF(RR_TIMESLICE_MS, "%li", &timeslice_ms);
> +
> +	TST_EXP_EXPR(timeslice_ms > 0,
> +	             "timeslice_ms > 0 after reset to default");
> +}
> +
> +static void rt_period_us_einval(void)
> +{
> +	TST_EXP_FAIL(write(period_fd, "0", 2), EINVAL,
Why not 1 as 3rd write() parameter?

> +	             "echo 0 > "RT_PERIOD_US);
nit: I'd add blank line here (readability).
> +	TST_EXP_FAIL(write(period_fd, "-1", 2), EINVAL,
> +	             "echo -1 > "RT_PERIOD_US);
> +}
> +
> +static void rt_runtime_us_einval(void)
> +{
> +	TST_EXP_FAIL(write(runtime_fd, "-2", 2), EINVAL,
> +	             "echo -2 > "RT_RUNTIME_US);
> +}
> +
> +static void rt_runtime_us_le_period_us(void)
> +{
> +	int period_us;
> +	char buf[32];
> +
> +	SAFE_FILE_SCANF(RT_PERIOD_US, "%i", &period_us);
> +
> +	sprintf(buf, "%i", period_us+1);
> +
> +	TST_EXP_FAIL(write(runtime_fd, buf, strlen(buf)), EINVAL,
> +	             "echo rt_period_us+1 > "RT_RUNTIME_US);
4x use of the same code, but I agree it's not worth of creating a function, as
the code is simple enough and probably more readable.

> +}
> +
> +static void verify_sched_proc(void)
> +{
Is there any value to print content of /proc/sys/kernel/sched_rt_runtime_us
before writing into it?

The rest LGTM.

Reviewed-by: Petr Vorel <pvorel@suse.cz>

Kind regards,
Petr

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  parent reply	other threads:[~2023-09-01 16:15 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-01 14:44 [LTP] [PATCH] sched: add sched sysctl sanity test Cyril Hrubis
2023-09-01 15:53 ` Cyril Hrubis
2023-09-01 16:15 ` Petr Vorel [this message]
2023-09-01 17:48 ` Petr Vorel
2023-10-02  8:26 ` Richard Palethorpe
2023-10-02 11:09   ` Cyril Hrubis
2023-10-03  8:18     ` Richard Palethorpe
2023-10-03  8:54     ` Cyril Hrubis
2023-10-04  9:22       ` Richard Palethorpe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230901161528.GA364687@pevik \
    --to=pvorel@suse.cz \
    --cc=chrubis@suse.cz \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.