Skip to contentSkip to conversation

linux-next: manual merge of the akpm-current tree with the kselftest tree

PATCH Applied Stephen Rothwell 3 participants 10 messages Jun 28, 2017 – Jun 30, 2017

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

Hi all,

Today's linux-next merge of the akpm-current tree got conflicts in:

tools/testing/selftests/sysctl/common_tests
tools/testing/selftests/sysctl/run_numerictests
tools/testing/selftests/sysctl/run_stringtests

between commit:

d644437a1dc6 ("tools/testing/selftests/sysctl: Add pre-check to the value of writes_strict")

from the kselftest tree and commit:

fed7038685f3 ("test_sysctl: add generic script to expand on tests")

from the akpm-current tree.

I fixed it up (I removed the files and so, for now I have effectively dropped the kselftest tree patch) and can carry the fix as necessary. This is now fixed as far as linux-next is concerned, but any non trivial conflicts should be mentioned to your upstream maintainer when your tree is submitted for merging. You may also want to consider cooperating with the maintainer of the conflicting tree to minimise any particularly complex conflicts.

Signature · 2 lines
Cheers,
Stephen Rothwell
maintainer
#1 lore raw
Quoted 18 lines · On Wed, 28 Jun 2017 18:31:11 +1000 Stephen Rothwell <[email protected]>…

Hi all,

Today's linux-next merge of the akpm-current tree got conflicts in:

tools/testing/selftests/sysctl/common_tests
tools/testing/selftests/sysctl/run_numerictests
tools/testing/selftests/sysctl/run_stringtests

between commit:

d644437a1dc6 ("tools/testing/selftests/sysctl: Add pre-check to the value of writes_strict")

from the kselftest tree and commit:

fed7038685f3 ("test_sysctl: add generic script to expand on tests")

from the akpm-current tree.

Quoted 8 lines

I fixed it up (I removed the files and so, for now I have effectively dropped the kselftest tree patch) and can carry the fix as necessary. This is now fixed as far as linux-next is concerned, but any non trivial conflicts should be mentioned to your upstream maintainer when your tree is submitted for merging. You may also want to consider cooperating with the maintainer of the conflicting tree to minimise any particularly complex conflicts.

urgh.

I'll drop

test_sysctl-add-dedicated-proc-sysctl-test-driver.patch test_sysctl-add-generic-script-to-expand-on-tests.patch test_sysctl-test-against-page_size-for-int.patch test_sysctl-add-simple-proc_dointvec-case.patch test_sysctl-add-simple-proc_douintvec-case.patch test_sysctl-test-against-int-proc_dointvec-array-support.patch

Luis, could you please redo these against the changes in linux-next and resend?

Thanks.

#2 lore raw
Quoted 40 lines · Andrew Morton
Quoted 18 lines · On Wed, 28 Jun 2017 18:31:11 +1000 Stephen Rothwell <[email protected]>…

Hi all,

Today's linux-next merge of the akpm-current tree got conflicts in:

tools/testing/selftests/sysctl/common_tests
tools/testing/selftests/sysctl/run_numerictests
tools/testing/selftests/sysctl/run_stringtests

between commit:

d644437a1dc6 ("tools/testing/selftests/sysctl: Add pre-check to the value of writes_strict")

from the kselftest tree and commit:

fed7038685f3 ("test_sysctl: add generic script to expand on tests")

from the akpm-current tree.

Quoted 8 lines

I fixed it up (I removed the files and so, for now I have effectively dropped the kselftest tree patch) and can carry the fix as necessary. This is now fixed as far as linux-next is concerned, but any non trivial conflicts should be mentioned to your upstream maintainer when your tree is submitted for merging. You may also want to consider cooperating with the maintainer of the conflicting tree to minimise any particularly complex conflicts.

urgh.

I'll drop

test_sysctl-add-dedicated-proc-sysctl-test-driver.patch test_sysctl-add-generic-script-to-expand-on-tests.patch test_sysctl-test-against-page_size-for-int.patch test_sysctl-add-simple-proc_dointvec-case.patch test_sysctl-add-simple-proc_douintvec-case.patch test_sysctl-test-against-int-proc_dointvec-array-support.patch

Quoted 2 lines

Luis, could you please redo these against the changes in linux-next and resend?

Coming right up!

Luis

#3 lore raw

v2 cover test_sysctl: fix up merge conflicts

In reply to Andrew Morton

Andrew,

as requested, this addresses the merge conflict present on kselftest/next on linux-next. The merge conflict was caused by Orson Zhai's patch titled, "tools/testing/selftests/sysctl: Add pre-check to the value of writes_strict" and my changes which shuffled the script around. I've made Orson's check a function, and integrated his exit strategy to restore the production sysctl writes_strict setting. To do this I've also added a PROD_SYCTL, which now users can also override through an environment variable.

These changes are also present on my linux-next 20170630-test-sysctl branch based on linux-next next20170630 [0]. If there are any questionms please let me know.

[0] https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux-next.git/log/?h=20170630-test-sysctl

Luis

Luis R. Rodriguez (6):
test_sysctl: add dedicated proc sysctl test driver
test_sysctl: add generic script to expand on tests
test_sysctl: test against PAGE_SIZE for int
test_sysctl: add simple proc_dointvec() case
test_sysctl: add simple proc_douintvec() case
test_sysctl: test against int proc_dointvec() array support

 lib/Kconfig.debug                               |  11 +
 lib/Makefile                                    |   1 +
 lib/test_sysctl.c                               | 148 +++++
 tools/testing/selftests/sysctl/Makefile         |   3 +-
 tools/testing/selftests/sysctl/common_tests     | 131 ----
 tools/testing/selftests/sysctl/config           |   1 +
 tools/testing/selftests/sysctl/run_numerictests |  10 -
 tools/testing/selftests/sysctl/run_stringtests  |  77 ---
 tools/testing/selftests/sysctl/sysctl.sh        | 774 ++++++++++++++++++++++++
 9 files changed, 936 insertions(+), 220 deletions(-)
 create mode 100644 lib/test_sysctl.c
 delete mode 100644 tools/testing/selftests/sysctl/common_tests
 create mode 100644 tools/testing/selftests/sysctl/config
 delete mode 100755 tools/testing/selftests/sysctl/run_numerictests
 delete mode 100755 tools/testing/selftests/sysctl/run_stringtests
 create mode 100755 tools/testing/selftests/sysctl/sysctl.sh
Signature · 1 line
2.11.0
#4 lore raw

PATCH v2 1/6 test_sysctl: add dedicated proc sysctl test driver

The existing tools/testing/selftests/sysctl/ tests include two test cases, but these use existing production kernel sysctl interfaces. We want to expand test coverage but we can't just be looking for random safe production values to poke at, that's just insane!

Instead just dedicate a test driver for debugging purposes and port the existing scripts to use it. This will make it easier for further tests to be added.

Subsequent patches will extend our test coverage for sysctl.

The stress test driver uses a new license (GPL on Linux, copyleft-next outside of Linux). Linus was fine with this [0] and later due to Ted's and Alans's request ironed out an "or" language clause to use [1] which is already present upstream.

[0] https://lkml.kernel.org/r/CA+55aFyhxcvD+q7tp+-yrSFDKfR0mOHgyEAe=f_94aKLsOu0Og@mail.gmail.com
[1] https://lkml.kernel.org/r/[email protected]

---
 lib/Kconfig.debug                               |  11 +++
 lib/Makefile                                    |   1 +
 lib/test_sysctl.c                               | 113 ++++++++++++++++++++++++
 tools/testing/selftests/sysctl/config           |   1 +
 tools/testing/selftests/sysctl/run_numerictests |   4 +-
 tools/testing/selftests/sysctl/run_stringtests  |   4 +-
 6 files changed, 130 insertions(+), 4 deletions(-)
 create mode 100644 lib/test_sysctl.c
 create mode 100644 tools/testing/selftests/sysctl/config
lib/Kconfig.debug +11 -0
index b0c35e0667df..dfa50b54f017 100644
@@ -1824,6 +1824,17 @@ config TEST_FIRMWARE
 
 	  If unsure, say N.
 
+config TEST_SYSCTL
+	tristate "sysctl test driver"
+	default n
+	depends on PROC_SYSCTL
+	help
+	  This builds the "test_sysctl" module. This driver enables to test the
+	  proc sysctl interfaces available to drivers safely without affecting
+	  production knobs which might alter system functionality.
+
+	  If unsure, say N.
+
 config TEST_UDELAY
 	tristate "udelay test driver"
 	default n
lib/Makefile +1 -0
index 678c6c38a991..40c18372b301 100644
@@ -46,6 +46,7 @@ obj-$(CONFIG_TEST_HEXDUMP) += test_hexdump.o
 obj-y += kstrtox.o
 obj-$(CONFIG_TEST_BPF) += test_bpf.o
 obj-$(CONFIG_TEST_FIRMWARE) += test_firmware.o
+obj-$(CONFIG_TEST_SYSCTL) += test_sysctl.o
 obj-$(CONFIG_TEST_HASH) += test_hash.o test_siphash.o
 obj-$(CONFIG_TEST_KASAN) += test_kasan.o
 obj-$(CONFIG_TEST_KSTRTOX) += test-kstrtox.o
lib/test_sysctl.c new file +113 -0

113 lines not on this page · raw message

tools/testing/selftests/sysctl/config new file +1 -0
new file mode 100644
index 000000000000..6ca14800d755
@@ -0,0 +1 @@
+CONFIG_TEST_SYSCTL=y
tools/testing/selftests/sysctl/run_numerictests +2 -2
index e6e76c93d948..c375ce0f4c15 100755
@@ -1,7 +1,7 @@
 #!/bin/sh
 
-SYSCTL="/proc/sys"
-TARGET="${SYSCTL}/vm/swappiness"
+SYSCTL="/proc/sys/debug/test_sysctl/"
+TARGET="${SYSCTL}/int_0001"
 ORIG=$(cat "${TARGET}")
 TEST_STR=$(( $ORIG + 1 ))
 
tools/testing/selftests/sysctl/run_stringtests +2 -2
index 857ec667fb02..a6f2618afeaa 100755
@@ -1,7 +1,7 @@
 #!/bin/sh
 
-SYSCTL="/proc/sys"
-TARGET="${SYSCTL}/kernel/domainname"
+SYSCTL="/proc/sys/debug/test_sysctl/"
+TARGET="${SYSCTL}/string_0001"
 ORIG=$(cat "${TARGET}")
 TEST_STR="Testing sysctl"
 
Signature · 1 line
2.11.0
#5 lore raw

PATCH v2 2/6 test_sysctl: add generic script to expand on tests

In reply to Luis R. Rodriguez

This adds a generic script to let us more easily add more tests cases. Since we really have only two types of tests cases just fold them into the one file. Each test unit is now identified into its separate function:

  # ./sysctl.sh -l
Test ID list:

TEST_ID x NUM_TEST

TEST_ID:   Test ID
NUM_TESTS: Number of recommended times to run the test

0001 x 1 - tests proc_dointvec_minmax()
0002 x 1 - tests proc_dostring()

For now we start off with what we had before, and run only each test once. We can now watch a test case until it fails:

./sysctl.sh -w 0002

We can also run a test case x number of times, say we want to run a test case 100 times:

./sysctl.sh -c 0001 100

To run a test case only once, for example:

./sysctl.sh -s 0002

The default settings are specified at the top of sysctl.sh.

Cc Kees Cook <[email protected]>
Cc "Eric W. Biederman" <[email protected]>
Cc Shuah Khan <[email protected]>
---
 tools/testing/selftests/sysctl/Makefile         |   3 +-
 tools/testing/selftests/sysctl/common_tests     | 131 -------
 tools/testing/selftests/sysctl/run_numerictests |  10 -
 tools/testing/selftests/sysctl/run_stringtests  |  77 ----
 tools/testing/selftests/sysctl/sysctl.sh        | 494 ++++++++++++++++++++++++
 5 files changed, 495 insertions(+), 220 deletions(-)
 delete mode 100644 tools/testing/selftests/sysctl/common_tests
 delete mode 100755 tools/testing/selftests/sysctl/run_numerictests
 delete mode 100755 tools/testing/selftests/sysctl/run_stringtests
 create mode 100755 tools/testing/selftests/sysctl/sysctl.sh
tools/testing/selftests/sysctl/Makefile +1 -2
index b3c33e071f10..95c320b354e8 100644
@@ -4,8 +4,7 @@
 # No binaries, but make sure arg-less "make" doesn't trigger "run_tests".
 all:
 
-TEST_PROGS := run_numerictests run_stringtests
-TEST_FILES := common_tests
+TEST_PROGS := sysctl.sh
 
 include ../lib.mk
 
tools/testing/selftests/sysctl/common_tests deleted +0 -131

131 lines not on this page · raw message

tools/testing/selftests/sysctl/run_numerictests deleted +0 -10
deleted file mode 100755
index c375ce0f4c15..000000000000
@@ -1,10 +0,0 @@
-#!/bin/sh
-
-SYSCTL="/proc/sys/debug/test_sysctl/"
-TARGET="${SYSCTL}/int_0001"
-ORIG=$(cat "${TARGET}")
-TEST_STR=$(( $ORIG + 1 ))
-
-. ./common_tests
-
-exit_test
tools/testing/selftests/sysctl/run_stringtests deleted +0 -77

77 lines not on this page · raw message

tools/testing/selftests/sysctl/sysctl.sh new file +494 -0

494 lines not on this page · raw message

Signature · 1 line
2.11.0
#6 lore raw

PATCH v2 3/6 test_sysctl: test against PAGE_SIZE for int

In reply to Luis R. Rodriguez

Add the following tests to ensure we do not regress:

o Test using a buffer full of space (PAGE_SIZE-1) followed by a single digit works

o Test using a buffer full of spaces (PAGE_SIZE or over) will fail

As tests increase instead of unloading the module and reloading it we can just do a shell reset_vals() with a reset to values we know are set at init on the driver.

Cc Kees Cook <[email protected]>
Cc "Eric W. Biederman" <[email protected]>
Cc Shuah Khan <[email protected]>
---
 tools/testing/selftests/sysctl/sysctl.sh | 66 ++++++++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)
tools/testing/selftests/sysctl/sysctl.sh +66 -0
index cbe1345d7c1d..6ec807576f7c 100755
@@ -75,6 +75,13 @@ function check_production_sysctl_writes_strict()
 			echo "1" > ${WRITES_STRICT}
 		fi
 	fi
+
+	if [ -z $PAGE_SIZE ]; then
+		PAGE_SIZE=$(getconf PAGESIZE)
+	fi
+	if [ -z $MAX_DIGITS ]; then
+		MAX_DIGITS=$(($PAGE_SIZE/8))
+	fi
 }
 
 test_reqs()
@@ -89,6 +96,10 @@ test_reqs()
 		echo "$0: You need perl installed"
 		exit 1
 	fi
+	if ! which getconf 2> /dev/null > /dev/null; then
+		echo "$0: You need getconf installed"
+		exit 1
+	fi
 }
 
 function load_req_mod()
@@ -103,6 +114,23 @@ function load_req_mod()
 	fi
 }
 
+reset_vals()
+{
+	VAL=""
+	TRIGGER=$(basename ${TARGET})
+	case "$TRIGGER" in
+		int_0001)
+			VAL="60"
+			;;
+		string_0001)
+			VAL="(none)"
+			;;
+		*)
+			;;
+	esac
+	echo -n $VAL > $TARGET
+}
+
 set_orig()
 {
 	if [ ! -z $TARGET ]; then
@@ -229,7 +257,42 @@ run_numerictests()
 	else
 		echo "ok"
 	fi
+	test_rc
+}
+
+# Your test must accept digits 3 and 4 to use this
+run_limit_digit()
+{
+	echo -n "Checking ignoring spaces up to PAGE_SIZE works on write ..."
+	reset_vals
 
+	LIMIT=$((MAX_DIGITS -1))
+	TEST_STR="3"
+	(perl -e 'print " " x '$LIMIT';'; echo "${TEST_STR}") | \
+		dd of="${TARGET}" 2>/dev/null
+
+	if ! verify "${TARGET}"; then
+		echo "FAIL" >&2
+		rc=1
+	else
+		echo "ok"
+	fi
+	test_rc
+
+	echo -n "Checking passing PAGE_SIZE of spaces fails on write ..."
+	reset_vals
+
+	LIMIT=$((MAX_DIGITS))
+	TEST_STR="4"
+	(perl -e 'print " " x '$LIMIT';'; echo "${TEST_STR}") | \
+		dd of="${TARGET}" 2>/dev/null
+
+	if verify "${TARGET}"; then
+		echo "FAIL" >&2
+		rc=1
+	else
+		echo "ok"
+	fi
 	test_rc
 }
 
@@ -305,15 +368,18 @@ run_stringtests()
 sysctl_test_0001()
 {
 	TARGET="${SYSCTL}/int_0001"
+	reset_vals
 	ORIG=$(cat "${TARGET}")
 	TEST_STR=$(( $ORIG + 1 ))
 
 	run_numerictests
+	run_limit_digit
 }
 
 sysctl_test_0002()
 {
 	TARGET="${SYSCTL}/string_0001"
+	reset_vals
 	ORIG=$(cat "${TARGET}")
 	TEST_STR="Testing sysctl"
 	# Only string sysctls support seeking/appending.
Signature · 1 line
2.11.0
#7 lore raw

PATCH v2 4/6 test_sysctl: add simple proc_dointvec() case

In reply to Luis R. Rodriguez

Test against a simple proc_dointvec() case. While at it, add a test against INT_MAX. Make sure INT_MAX works, and INT_MAX+1 will fail. Also test negative values work.

Cc Kees Cook <[email protected]>
Cc "Eric W. Biederman" <[email protected]>
Cc Shuah Khan <[email protected]>
---
 lib/test_sysctl.c                        | 11 ++++++
 tools/testing/selftests/sysctl/sysctl.sh | 62 ++++++++++++++++++++++++++++++++
 2 files changed, 73 insertions(+)
lib/test_sysctl.c +11 -0
index b2163bfb6eb2..1472e1ae4931 100644
@@ -41,11 +41,15 @@ static int i_one_hundred = 100;
 
 struct test_sysctl_data {
 	int int_0001;
+	int int_0002;
+
 	char string_0001[65];
 };
 
 static struct test_sysctl_data test_data = {
 	.int_0001 = 60,
+	.int_0002 = 1,
+
 	.string_0001 = "(none)",
 };
 
@@ -61,6 +65,13 @@ static struct ctl_table test_table[] = {
 		.extra2         = &i_one_hundred,
 	},
 	{
+		.procname	= "int_0002",
+		.data		= &test_data.int_0002,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec,
+	},
+	{
 		.procname	= "string_0001",
 		.data		= &test_data.string_0001,
 		.maxlen		= sizeof(test_data.string_0001),
tools/testing/selftests/sysctl/sysctl.sh +62 -0

98 lines not on this page · raw message

Signature · 1 line
2.11.0
#8 lore raw

PATCH v2 5/6 test_sysctl: add simple proc_douintvec() case

In reply to Luis R. Rodriguez

Test against a simple proc_douintvec() case. While at it, add a test against UINT_MAX. Make sure UINT_MAX works, and UINT_MAX+1 will fail and that negative values are not accepted.

Cc Kees Cook <[email protected]>
Cc "Eric W. Biederman" <[email protected]>
Cc Shuah Khan <[email protected]>
---
 lib/test_sysctl.c                        | 11 ++++++
 tools/testing/selftests/sysctl/sysctl.sh | 63 ++++++++++++++++++++++++++++++++
 2 files changed, 74 insertions(+)
lib/test_sysctl.c +11 -0
index 1472e1ae4931..53db3513ab08 100644
@@ -43,6 +43,8 @@ struct test_sysctl_data {
 	int int_0001;
 	int int_0002;
 
+	unsigned int uint_0001;
+
 	char string_0001[65];
 };
 
@@ -50,6 +52,8 @@ static struct test_sysctl_data test_data = {
 	.int_0001 = 60,
 	.int_0002 = 1,
 
+	.uint_0001 = 314,
+
 	.string_0001 = "(none)",
 };
 
@@ -72,6 +76,13 @@ static struct ctl_table test_table[] = {
 		.proc_handler	= proc_dointvec,
 	},
 	{
+		.procname	= "uint_0001",
+		.data		= &test_data.uint_0001,
+		.maxlen		= sizeof(unsigned int),
+		.mode		= 0644,
+		.proc_handler	= proc_douintvec,
+	},
+	{
 		.procname	= "string_0001",
 		.data		= &test_data.string_0001,
 		.maxlen		= sizeof(test_data.string_0001),
tools/testing/selftests/sysctl/sysctl.sh +63 -0

99 lines not on this page · raw message

Signature · 1 line
2.11.0
#9 lore raw

PATCH v2 6/6 test_sysctl: test against int proc_dointvec() array support

In reply to Luis R. Rodriguez

Add a few initial respective tests for an array:

o Echoing values separated by spaces works
o Echoing only first elements will set first elements
o Confirm PAGE_SIZE limit still applies even if an array is used

Cc Kees Cook <[email protected]>
Cc "Eric W. Biederman" <[email protected]>
Cc Shuah Khan <[email protected]>
---
 lib/test_sysctl.c                        | 13 +++++
 tools/testing/selftests/sysctl/sysctl.sh | 89 ++++++++++++++++++++++++++++++++
 2 files changed, 102 insertions(+)
lib/test_sysctl.c +13 -0
index 53db3513ab08..3dd801c1c85b 100644
@@ -42,6 +42,7 @@ static int i_one_hundred = 100;
 struct test_sysctl_data {
 	int int_0001;
 	int int_0002;
+	int int_0003[4];
 
 	unsigned int uint_0001;
 
@@ -52,6 +53,11 @@ static struct test_sysctl_data test_data = {
 	.int_0001 = 60,
 	.int_0002 = 1,
 
+	.int_0003[0] = 0,
+	.int_0003[1] = 1,
+	.int_0003[2] = 2,
+	.int_0003[3] = 3,
+
 	.uint_0001 = 314,
 
 	.string_0001 = "(none)",
@@ -76,6 +82,13 @@ static struct ctl_table test_table[] = {
 		.proc_handler	= proc_dointvec,
 	},
 	{
+		.procname	= "int_0003",
+		.data		= &test_data.int_0003,
+		.maxlen		= sizeof(test_data.int_0003),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec,
+	},
+	{
 		.procname	= "uint_0001",
 		.data		= &test_data.uint_0001,
 		.maxlen		= sizeof(unsigned int),
tools/testing/selftests/sysctl/sysctl.sh +89 -0

125 lines not on this page · raw message

Signature · 1 line
2.11.0