All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luis Chamberlain <mcgrof@kernel.org>
To: Vlastimil Babka <vbabka@suse.cz>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Kees Cook <keescook@chromium.org>,
	Iurii Zaikin <yzaikin@google.com>,
	linux-kernel@vger.kernel.org, linux-api@vger.kernel.org,
	linux-mm@kvack.org, Ivan Teterevkov <ivan.teterevkov@nutanix.com>,
	Michal Hocko <mhocko@kernel.org>,
	David Rientjes <rientjes@google.com>,
	Matthew Wilcox <willy@infradead.org>,
	"Eric W . Biederman" <ebiederm@xmission.com>,
	"Guilherme G . Piccoli" <gpiccoli@canonical.com>,
	Alexey Dobriyan <adobriyan@gmail.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Christian Brauner <christian.brauner@ubuntu.com>,
	Masami Hiramatsu <mhiramat@kernel.org>
Subject: Re: [PATCH v3 5/5] lib/test_sysctl: support testing of sysctl. boot parameter
Date: Mon, 27 Apr 2020 18:39:13 +0000	[thread overview]
Message-ID: <20200427183913.GH11244@42.do-not-panic.com> (raw)
In-Reply-To: <20200427180433.7029-6-vbabka@suse.cz>

On Mon, Apr 27, 2020 at 08:04:33PM +0200, Vlastimil Babka wrote:
> Testing is done by a new parameter debug.test_sysctl.boot_int which defaults to
> 0 and it's expected that the tester passes a boot parameter that sets it to 1.
> The test checks if it's set to 1. To distinguish true failure from parameter
> not being set, the test checks /proc/cmdline for the expected parameter, and
> whether test_sysctl is built-in and not a module.
> 
> Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
> ---
>  lib/test_sysctl.c                        | 13 +++++++++
>  tools/testing/selftests/sysctl/sysctl.sh | 36 ++++++++++++++++++++++++
>  2 files changed, 49 insertions(+)
> 
> diff --git a/lib/test_sysctl.c b/lib/test_sysctl.c
> index 566dad3f4196..84eaae22d3a6 100644
> --- a/lib/test_sysctl.c
> +++ b/lib/test_sysctl.c
> @@ -44,6 +44,8 @@ struct test_sysctl_data {
>  	int int_0002;
>  	int int_0003[4];
>  
> +	int boot_int;
> +
>  	unsigned int uint_0001;
>  
>  	char string_0001[65];
> @@ -61,6 +63,8 @@ static struct test_sysctl_data test_data = {
>  	.int_0003[2] = 2,
>  	.int_0003[3] = 3,
>  
> +	.boot_int = 0,
> +
>  	.uint_0001 = 314,
>  
>  	.string_0001 = "(none)",
> @@ -91,6 +95,15 @@ static struct ctl_table test_table[] = {
>  		.mode		= 0644,
>  		.proc_handler	= proc_dointvec,
>  	},
> +	{
> +		.procname	= "boot_int",
> +		.data		= &test_data.boot_int,
> +		.maxlen		= sizeof(test_data.boot_int),
> +		.mode		= 0644,
> +		.proc_handler	= proc_dointvec,
> +		.extra1		= SYSCTL_ZERO,
> +		.extra2         = SYSCTL_ONE,
> +	},
>  	{
>  		.procname	= "uint_0001",
>  		.data		= &test_data.uint_0001,
> diff --git a/tools/testing/selftests/sysctl/sysctl.sh b/tools/testing/selftests/sysctl/sysctl.sh
> index ce1eeea6f769..ef6417b8067b 100755
> --- a/tools/testing/selftests/sysctl/sysctl.sh
> +++ b/tools/testing/selftests/sysctl/sysctl.sh
> @@ -39,6 +39,7 @@ ALL_TESTS="$ALL_TESTS 0003:1:1:int_0002"
>  ALL_TESTS="$ALL_TESTS 0004:1:1:uint_0001"
>  ALL_TESTS="$ALL_TESTS 0005:3:1:int_0003"
>  ALL_TESTS="$ALL_TESTS 0006:50:1:bitmap_0001"
> +ALL_TESTS="$ALL_TESTS 0007:1:1:boot_int"
>  
>  test_modprobe()
>  {
> @@ -752,6 +753,40 @@ sysctl_test_0006()
>  	run_bitmaptest
>  }
>  
> +sysctl_test_0007()
> +{
> +	TARGET="${SYSCTL}/boot_int"
> +	if [ -d $DIR ]; then
> +		echo "Boot param test only possible sysctl_test is built-in, not module:"
> +		cat $TEST_DIR/config >&2
> +		return 0
> +	fi

Nice, also we could just require

diff --git a/tools/testing/selftests/sysctl/config b/tools/testing/selftests/sysctl/config
index 6ca14800d755..34461cc99a2b 100644
--- a/tools/testing/selftests/sysctl/config
+++ b/tools/testing/selftests/sysctl/config
@@ -1 +1,3 @@
 CONFIG_TEST_SYSCTL=y
+CONFIG_IKCONFIG=y
+CONFIG_IKCONFIG_PROC=y

tools/testing/selftests/firmware/fw_lib.sh then has a kconfig_has()
which can verify the exact config.

> +
> +	echo -n "Testing if $TARGET is set to 1 ..."
> +	ORIG=$(cat "${TARGET}")

This would fail if someone uses this script to test an older kernel, and
the scripts in selftests are supposed to work with older kernels. One
way to address this would be to just see if the file exists first and
ignore the test if the $SYSCTL directory exists but the file $TARGET
does not.

For now we can just do this:

if [ ! -d $TARGET ]; then
	echo "Skipping test for $TARGET as it is not present ..."
	return 0
fi

  Luis

  reply	other threads:[~2020-04-27 18:39 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-27 18:04 [PATCH v3 0/5] support setting sysctl parameters from kernel command line Vlastimil Babka
2020-04-27 18:04 ` [PATCH v3 1/5] kernel/sysctl: " Vlastimil Babka
2020-04-27 18:33   ` Andrew Morton
2020-04-28  8:09     ` Vlastimil Babka
2020-04-28 10:18       ` Michal Hocko
2020-04-27 18:04 ` [PATCH v3 2/5] kernel/sysctl: support handling command line aliases Vlastimil Babka
2020-04-27 18:04 ` [PATCH v3 3/5] kernel/hung_task convert hung_task_panic boot parameter to sysctl Vlastimil Babka
2020-04-27 18:04 ` [PATCH v3 4/5] tools/testing/selftests/sysctl/sysctl.sh: support CONFIG_TEST_SYSCTL=y Vlastimil Babka
2020-04-27 18:39   ` Luis Chamberlain
2020-04-27 18:04 ` [PATCH v3 5/5] lib/test_sysctl: support testing of sysctl. boot parameter Vlastimil Babka
2020-04-27 18:39   ` Luis Chamberlain [this message]
2020-05-11 11:05     ` Vlastimil Babka
2020-05-11 18:31       ` Luis Chamberlain
2020-05-13  8:58         ` Vlastimil Babka
2020-05-13 13:15           ` Luis Chamberlain
2020-05-13 13:17             ` Luis Chamberlain
2020-05-13 13:17               ` Luis Chamberlain
2020-05-15 16:02               ` Vlastimil Babka

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=20200427183913.GH11244@42.do-not-panic.com \
    --to=mcgrof@kernel.org \
    --cc=adobriyan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=christian.brauner@ubuntu.com \
    --cc=ebiederm@xmission.com \
    --cc=gpiccoli@canonical.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=ivan.teterevkov@nutanix.com \
    --cc=keescook@chromium.org \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhiramat@kernel.org \
    --cc=mhocko@kernel.org \
    --cc=rientjes@google.com \
    --cc=tglx@linutronix.de \
    --cc=vbabka@suse.cz \
    --cc=willy@infradead.org \
    --cc=yzaikin@google.com \
    /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.