sysctl: add dedicated stress test driver
Subsystems (4)
cover sysctl: add dedicated stress test driver
Andrew,
This series adds a dedicated proc sysctl stress test driver and extends our current set of tests. I spun this off from a larger series to first get the basic knobs in place for unsigned int, which are now merged in your tree, so this series depends on those patches.
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.
If there are any questions please let me know.
[0] https://lkml.kernel.org/r/CA+55aFyhxcvD+q7tp+-yrSFDKfR0mOHgyEAe=f_94aKLsOu0Og@mail.gmail.com
[1] https://lkml.kernel.org/r/[email protected]
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 | 109 ---- 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 | 745 ++++++++++++++++++++++++ 9 files changed, 907 insertions(+), 198 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
PATCH 1/6 test_sysctl: add dedicated proc sysctl test driver
Although we have had tools/testing/selftests/sysctl/ with two test cases these use existing kernel sysctl interfaces. We want to expand test coverage, we can't just be looking for random safe production values to poke at, 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.
--- 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
@@ -1782,6 +1782,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
@@ -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
@@ -0,0 +1 @@ +CONFIG_TEST_SYSCTL=y
tools/testing/selftests/sysctl/run_numerictests +2 -2
@@ -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
@@ -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
PATCH 2/6 test_sysctl: add generic script to expand on tests
In reply to Luis R. RodriguezThis 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.
--- tools/testing/selftests/sysctl/Makefile | 3 +- tools/testing/selftests/sysctl/common_tests | 109 ------ tools/testing/selftests/sysctl/run_numerictests | 10 - tools/testing/selftests/sysctl/run_stringtests | 77 ---- tools/testing/selftests/sysctl/sysctl.sh | 466 ++++++++++++++++++++++++ 5 files changed, 467 insertions(+), 198 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
@@ -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 -109
109 lines not on this page · raw message
tools/testing/selftests/sysctl/run_numerictests deleted +0 -10
@@ -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 $rc
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 +466 -0
466 lines not on this page · raw message
Signature · 1 line
2.11.0
PATCH 3/6 test_sysctl: test against PAGE_SIZE for int
In reply to Luis R. RodriguezAdd 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.
--- tools/testing/selftests/sysctl/sysctl.sh | 65 ++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+)
tools/testing/selftests/sysctl/sysctl.sh +65 -0
@@ -53,6 +53,12 @@ function allow_user_defaults() if [ -z $SYSCTL ]; then SYSCTL="/proc/sys/debug/test_sysctl" fi + if [ -z $PAGE_SIZE ]; then + PAGE_SIZE=$(getconf PAGESIZE) + fi + if [ -z $MAX_DIGITS ]; then + MAX_DIGITS=$(($PAGE_SIZE/8)) + fi } test_reqs()
@@ -67,6 +73,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()
@@ -81,6 +91,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
@@ -202,7 +229,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 }
@@ -278,15 +340,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
PATCH 4/6 test_sysctl: add simple proc_dointvec() case
In reply to Luis R. RodriguezTest 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.
--- lib/test_sysctl.c | 11 ++++++ tools/testing/selftests/sysctl/sysctl.sh | 62 ++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+)
lib/test_sysctl.c +11 -0
@@ -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
PATCH 5/6 test_sysctl: add simple proc_douintvec() case
In reply to Luis R. RodriguezTest 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.
--- lib/test_sysctl.c | 11 ++++++ tools/testing/selftests/sysctl/sysctl.sh | 63 ++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+)
lib/test_sysctl.c +11 -0
@@ -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
PATCH 6/6 test_sysctl: test against int proc_dointvec() array support
In reply to Luis R. RodriguezAdd 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
--- lib/test_sysctl.c | 13 +++++ tools/testing/selftests/sysctl/sysctl.sh | 89 ++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+)
lib/test_sysctl.c +13 -0
@@ -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